Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var disassociate = function (relationshipName, targetEntityName, targetId, relatedEntityName, relatedBusinessEntities, callback) {
- ///<summary>
- /// Sends synchronous/asynchronous request to disassociate records.
- ///</summary>
- ///<param name="relationshipName" type="String">
- /// A JavaScript String corresponding to the relationship name
- /// that is used for disassociate operations.
- /// </param>
- ///<param name="targetEntityName" type="String">
- /// A JavaScript String corresponding to the schema name of the target entity
- /// that is used for disassociate operations.
- /// </param>
- ///<param name="targetId" type="String">
- /// A JavaScript String corresponding to the GUID of the target entity
- /// that is used for disassociate operations.
- /// </param>
- ///<param name="relatedEntityName" type="String">
- /// A JavaScript String corresponding to the schema name of the related entity
- /// that is used for disassociate operations.
- /// </param>
- ///<param name="relationshipBusinessEntities" type="Array">
- /// A JavaScript Array corresponding to the collection of the related entities as BusinessEntity
- /// that is used for disassociate operations.
- /// </param>
- ///<param name="callback" type="Function">
- /// A Function used for asynchronous request. If not defined, it sends a synchronous request.
- /// </param>
- var relatedEntities = relatedBusinessEntities;
- relatedEntities = isArray(relatedEntities) ? relatedEntities : [relatedEntities];
- var output = [];
- for (var i = 0; i < relatedEntities.length; i++) {
- if (relatedEntities[i].id != '') {
- output.push("<a:EntityReference>",
- "<a:Id>", relatedEntities[i].id, "</a:Id>",
- "<a:LogicalName>", relatedEntityName, "</a:LogicalName>",
- "<a:Name i:nil='true' />",
- "</a:EntityReference>");
- }
- }
- var relatedXml = output.join("");
- var request = [
- "<request i:type='a:DisassociateRequest' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'>",
- "<a:Parameters xmlns:b='http://schemas.datacontract.org/2004/07/System.Collections.Generic'>",
- "<a:KeyValuePairOfstringanyType>",
- "<b:key>Target</b:key>",
- "<b:value i:type='a:EntityReference'>",
- "<a:Id>", targetId, "</a:Id>",
- "<a:LogicalName>", targetEntityName, "</a:LogicalName>",
- "<a:Name i:nil='true' />",
- "</b:value>",
- "</a:KeyValuePairOfstringanyType>",
- "<a:KeyValuePairOfstringanyType>",
- "<b:key>Relationship</b:key>",
- "<b:value i:type='a:Relationship'>",
- "<a:PrimaryEntityRole i:nil='true' />",
- "<a:SchemaName>", relationshipName, "</a:SchemaName>",
- "</b:value>",
- "</a:KeyValuePairOfstringanyType>",
- "<a:KeyValuePairOfstringanyType>",
- "<b:key>RelatedEntities</b:key>",
- "<b:value i:type='a:EntityReferenceCollection'>",
- relatedXml,
- "</b:value>",
- "</a:KeyValuePairOfstringanyType>",
- "</a:Parameters>",
- "<a:RequestId i:nil='true' />",
- "<a:RequestName>Disassociate</a:RequestName>",
- "</request>"
- ].join("");
- var async = !!callback;
- return doRequest(request, "Execute", async, function (resultXml) {
- var response = jQuery(resultXml).find('ExecuteResult').eq(0);
- var result = crmXmlDecode(response.text());
- if (!async)
- return result;
- else
- callback(result);
- // ReSharper disable NotAllPathsReturnValue
- });
- // ReSharper restore NotAllPathsReturnValue
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement