Archive

Archive for March 29, 2012

Associating entities with n:n relationship using Jscript

March 29, 2012 1 comment

Hi,

Below is the Jscript to associate two entity records, which are having (N:N) relationship.

function AssociateEntities(relationshipSchemaName, entity1Name, entity1Id, entity2Name, entity2Id) {

var xmlSoapBody = “<Execute xmlns=’http://schemas.microsoft.com/crm/2007/WebServices’>&#8221;

+ ”  <Request xsi:type=’AssociateEntitiesRequest’>”

+ ”    <Moniker1>”

+ ”      <Name xmlns=’http://schemas.microsoft.com/crm/2006/CoreTypes’>&#8221; + entity1Name + “</Name>”

+ ”      <Id xmlns=’http://schemas.microsoft.com/crm/2006/CoreTypes’>&#8221; + entity1Id + “</Id>”

+ ”    </Moniker1>”

+ ”    <Moniker2>”

+ ”      <Name xmlns=’http://schemas.microsoft.com/crm/2006/CoreTypes’>&#8221; + entity2Name + “</Name>”

+ ”      <Id xmlns=’http://schemas.microsoft.com/crm/2006/CoreTypes’>&#8221; + entity2Id + “</Id>”

+ ”    </Moniker2>”

+ ”    <RelationshipName>” + relationshipSchemaName + “</RelationshipName>”

+ ”  </Request>”

+ “</Execute>”;

ExecuteSOAP(“/MSCRMServices/2007/CrmService.asmx”, xmlSoapBody, “http://schemas.microsoft.com/crm/2007/WebServices/Execute&#8221;, false);

}

 function ExecuteSOAP(serviceUrl, xmlSoapBody, soapActionHeader) {

var xmlReq = “<?xml version=’1.0′ encoding=’utf-8′?>”

+ “<soap:Envelope xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/'&#8221;

+ ”  xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance'&#8221;

+ ”  xmlns:xsd=’http://www.w3.org/2001/XMLSchema’>&#8221;

+ GenerateAuthenticationHeader()

+ ”  <soap:Body>”

+ xmlSoapBody

+ ”  </soap:Body>”

+ “</soap:Envelope>”;

var httpObj = new ActiveXObject(“Msxml2.XMLHTTP”);

httpObj.open(“POST”, serviceUrl, false);

httpObj.setRequestHeader(“SOAPAction”, soapActionHeader);

httpObj.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);

httpObj.setRequestHeader(“Content-Length”, xmlReq.length);

httpObj.send(xmlReq);

var resultXml = httpObj.responseXML;

var errorCount = resultXml.selectNodes(“//error”).length;

if (errorCount != 0) {

var msg = resultXml.selectSingleNode(“//description”).nodeTypedValue;

alert(“Error while association; ” + msg);

return null;

} else {

alert(“Success!!!”);

return resultXml;

}

}

How do I call these functions :-

  • Let’s assume, you have N:N relationship between entityA & entity with relationship name (“new_entityAentityB”)

    var relationshipName = ” new_entityAentityB “;

var entityA_SchemaName = “new_entitya”;

var entityB_SchemaName = “new_entityb”;

var entiyA_Id = “{}”; //GUID of entityA record

var entiyB_Id = “{}”; //GUID of entityB record

AssociateEntities(relationshipName, entityA_SchemaName, entiyA_Id, entityB_SchemaName, entiyB_Id);

Note :- If you copy above functions, please replace double quote & single quote symbols with keyboard symbols.

Hope it helps 🙂

Could not load type System.ServiceModel.Activation.HttpModule exception

Hi,

I was getting below exception, When I hosted my asp.net web application on IIS and tried to browse my .aspx page.

Could not load type error

Could not load type error

Reason :-

  • The reason could be, when the IIS is installed after the installation of .NET Framework 4, or if the 3.0 version of the WCF Http Activation module is installed after installing IIS and .NET Framework 4.

Fix :-

  • To resolve this issue follow bellow steps
    • Open Command Prompt (Run -> cmd)
    • Navigate to the path “%windir%\Microsoft.NET\Framework\v4.0.30319”
    • Type “aspnet_regiis.exe /iru” and press enter button.
    Run Command Aspnet_iis.exe

    Run Command Aspnet_iis.exe

    • Restart the IIS

Hope it helps 🙂