Thursday, July 28, 2011

Remove Solution Components From an Unmanaged Solution Using .NET or Jscript in Microsoft Dynamics CRM 2011

This illustration shows how to remove solution components from an unmanaged solution in Microsoft Dynamics CRM 2011 in .NET or Jscript with the RemoveSolutionComponentRequest.

Ok, here is what the code looks like!

//perform a retrievemultiple on solutioncomponent entities for the given solution
RetrieveMultipleRequest rmr = new RetrieveMultipleRequest();
RetrieveMultipleResponse resp = new RetrieveMultipleResponse();
QueryExpression query = new QueryExpression()
{
    EntityName = "solutioncomponent",
    ColumnSet = new ColumnSet(true),
    Criteria = new FilterExpression
    {
        FilterOperator = LogicalOperator.And,
        Conditions = 
       {
           new ConditionExpression
           {
               AttributeName = "solutionid",
               Operator = ConditionOperator.Equal,
               Values = { "4964C137-1AB9-E011-8D99-1CC1DE7955DB" }
           }
       }
    }
};
rmr.Query = query;
resp = (RetrieveMultipleResponse)slos.Execute(rmr);

//use RemoveSolutionComponentRequest to remove solution elements from solution.
foreach (SolutionComponent sc in resp.EntityCollection.Entities)
{

    RemoveSolutionComponentRequest removereq = new RemoveSolutionComponentRequest();
    removereq.SolutionUniqueName = "testjamiesolution";

    removereq.ComponentId = sc.ObjectId.Value;
    removereq.ComponentType = sc.ComponentType.Value;
    RemoveSolutionComponentResponse removeresp = (RemoveSolutionComponentResponse)slos.Execute(removereq);
}

If you need help instantiating a service object in .NET within a plugin check out this post:
http://mileyja.blogspot.com/2011/04/instantiating-service-object-within.html

I formatted the RemoveSolutionComponentRequest call up for you in Jscript using the CRM 2011 Soap Formatter. Available at: http://crm2011soap.codeplex.com/

Now in Jscript


This example is asynchronous, if you want to learn how to make JScript SOAP calls synchronously please visit this post: http://mileyja.blogspot.com/2011/07/using-jscript-to-access-soap-web.html

if (typeof (SDK) == "undefined")
   { SDK = { __namespace: true }; }
       //This will establish a more unique namespace for functions in this library. This will reduce the 
       // potential for functions to be overwritten due to a duplicate name when the library is loaded.
       SDK.RemoveSolutionComponent = {
           _getServerUrl: function () {
               ///<summary>
               /// Returns the URL for the SOAP endpoint using the context information available in the form
               /// or HTML Web resource.
               ///</summary>
               var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
               var serverUrl = "";
               if (typeof GetGlobalContext == "function") {
                   var context = GetGlobalContext();
                   serverUrl = context.getServerUrl();
               }
               else {
                   if (typeof Xrm.Page.context == "object") {
                         serverUrl = Xrm.Page.context.getServerUrl();
                   }
                   else
                   { throw new Error("Unable to access the server URL"); }
                   }
                  if (serverUrl.match(/\/$/)) {
                       serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                   } 
                   return serverUrl + OrgServicePath;
               }, 
           RemoveSolutionComponentRequest: function () {
               var requestMain = ""
               requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
               requestMain += "  <s:Body>";
               requestMain += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
               requestMain += "      <request i:type=\"b:RemoveSolutionComponentRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
               requestMain += "        <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
               requestMain += "          <a:KeyValuePairOfstringanyType>";
               requestMain += "            <c:key>ComponentId</c:key>";
               requestMain += "            <c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">95e930c5-812a-44e8-85c9-154cd5f59465</c:value>";
               requestMain += "          </a:KeyValuePairOfstringanyType>";
               requestMain += "          <a:KeyValuePairOfstringanyType>";
               requestMain += "            <c:key>ComponentType</c:key>";
               requestMain += "            <c:value i:type=\"d:int\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">1</c:value>";
               requestMain += "          </a:KeyValuePairOfstringanyType>";
               requestMain += "          <a:KeyValuePairOfstringanyType>";
               requestMain += "            <c:key>SolutionUniqueName</c:key>";
               requestMain += "            <c:value i:type=\"d:string\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">testjamiesolution</c:value>";
               requestMain += "          </a:KeyValuePairOfstringanyType>";
               requestMain += "        </a:Parameters>";
               requestMain += "        <a:RequestId i:nil=\"true\" />";
               requestMain += "        <a:RequestName>RemoveSolutionComponent</a:RequestName>";
               requestMain += "      </request>";
               requestMain += "    </Execute>";
               requestMain += "  </s:Body>";
               requestMain += "</s:Envelope>";
               var req = new XMLHttpRequest();
               req.open("POST", SDK.RemoveSolutionComponent._getServerUrl(), true)
               // Responses will return XML. It isn't possible to return JSON.
               req.setRequestHeader("Accept", "application/xml, text/xml, */*");
               req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
               req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
               var successCallback = null;
               var errorCallback = null;
               req.onreadystatechange = function () { SDK.RemoveSolutionComponent.RemoveSolutionComponentResponse(req, successCallback, errorCallback); };
               req.send(requestMain);
           },
       RemoveSolutionComponentResponse: function (req, successCallback, errorCallback) {
               ///<summary>
               /// Recieves the assign response
               ///</summary>
               ///<param name="req" Type="XMLHttpRequest">
               /// The XMLHttpRequest response
               ///</param>
               ///<param name="successCallback" Type="Function">
               /// The function to perform when an successfult response is returned.
               /// For this message no data is returned so a success callback is not really necessary.
               ///</param>
               ///<param name="errorCallback" Type="Function">
               /// The function to perform when an error is returned.
               /// This function accepts a JScript error returned by the _getError function
               ///</param>
               if (req.readyState == 4) {
               if (req.status == 200) {
               if (successCallback != null)
               { successCallback(); }
               }
               else {
                   errorCallback(SDK.RemoveSolutionComponent._getError(req.responseXML));
               }
           }
       },
       _getError: function (faultXml) {
           ///<summary>
           /// Parses the WCF fault returned in the event of an error.
           ///</summary>
           ///<param name="faultXml" Type="XML">
           /// The responseXML property of the XMLHttpRequest response.
           ///</param>
           var errorMessage = "Unknown Error (Unable to parse the fault)";
           if (typeof faultXml == "object") {
               try {
                   var bodyNode = faultXml.firstChild.firstChild;
                   //Retrieve the fault node
                   for (var i = 0; i < bodyNode.childNodes.length; i++) {
                       var node = bodyNode.childNodes[i];
                       //NOTE: This comparison does not handle the case where the XML namespace changes
                       if ("s:Fault" == node.nodeName) {
                       for (var j = 0; j < node.childNodes.length; j++) {
                           var faultStringNode = node.childNodes[j];
                           if ("faultstring" == faultStringNode.nodeName) {
                               errorMessage = faultStringNode.text;
                               break;
                           }
                       }
                       break;
                   }
               }
           }
           catch (e) { };
        }
        return new Error(errorMessage);
     },
 __namespace: true
};




To understand how to parse the response please review my post on using the DOM parser.
Now you can call the SDK.SAMPLES.RemoveSolutionComponentRequest function from your form jscript handler.
Thats all there is to it!

I hope this helps!

Wednesday, July 27, 2011

Update Entity Metadata Using Jscript or .NET in Microsoft Dynamics CRM 2011 with UpdateEntityRequest

This illustration shows how to update an entities metadata in Microsoft Dynamics CRM 2011 in code with the UpdateEntityRequest.   This example will be given in Jscript (SOAP) and in C# (.NET).

Ok, here is what the code looks like!
First in C#:

//first retrieve entity metadata you want to update
RetrieveEntityRequest req = new RetrieveEntityRequest();
req.LogicalName = "account";
RetrieveEntityResponse resp = (RetrieveEntityResponse)slos.Execute(req);

EntityMetadata entity = resp.EntityMetadata;

//change properties
entity.Description = new Label("my test description", 1033);

//Now update the entity
UpdateEntityRequest updatereq = new UpdateEntityRequest();
updatereq.Entity = entity;

UpdateEntityResponse updateresp = (UpdateEntityResponse)slos.Execute(updatereq);

If you need help instantiating a service object in .NET within a plugin check out this post:
http://mileyja.blogspot.com/2011/04/instantiating-service-object-within.html

Now here is the Jscript nicely formatted by the CRM 2011 SOAP formatter. Available at: http://crm2011soap.codeplex.com/

Now in Jscript


This example is asynchronous, if you want to learn how to make JScript SOAP calls synchronously please visit this post: http://mileyja.blogspot.com/2011/07/using-jscript-to-access-soap-web.html

if (typeof (SDK) == "undefined")
   { SDK = { __namespace: true }; }
       //This will establish a more unique namespace for functions in this library. This will reduce the 
       // potential for functions to be overwritten due to a duplicate name when the library is loaded.
       SDK.SAMPLES = {
           _getServerUrl: function () {
               ///<summary>
               /// Returns the URL for the SOAP endpoint using the context information available in the form
               /// or HTML Web resource.
               ///</summary>
               var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
               var serverUrl = "";
               if (typeof GetGlobalContext == "function") {
                   var context = GetGlobalContext();
                   serverUrl = context.getServerUrl();
               }
               else {
                   if (typeof Xrm.Page.context == "object") {
                         serverUrl = Xrm.Page.context.getServerUrl();
                   }
                   else
                   { throw new Error("Unable to access the server URL"); }
                   }
                  if (serverUrl.match(/\/$/)) {
                       serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                   } 
                   return serverUrl + OrgServicePath;
               }, 
           UpdateEntityRequest: function () {
               var requestMain = ""
               requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
               requestMain += "  <s:Body>";
               requestMain += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
               requestMain += "      <request i:type=\"a:UpdateEntityRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
               requestMain += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
               requestMain += "          <a:KeyValuePairOfstringanyType>";
               requestMain += "            <b:key>Entity</b:key>";
               requestMain += "            <b:value i:type=\"c:EntityMetadata\" xmlns:c=\"http://schemas.microsoft.com/xrm/2011/Metadata\">";
               requestMain += "              <c:MetadataId>70816501-edb9-4740-a16c-6a5efbc05d84</c:MetadataId>";
               requestMain += "              <c:ActivityTypeMask>1</c:ActivityTypeMask>";
               requestMain += "              <c:Attributes i:nil=\"true\" />";
               requestMain += "              <c:AutoRouteToOwnerQueue>false</c:AutoRouteToOwnerQueue>";
               requestMain += "              <c:CanBeInManyToMany>";
               requestMain += "                <a:CanBeChanged>false</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>canbeinmanytomany</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:CanBeInManyToMany>";
               requestMain += "              <c:CanBePrimaryEntityInRelationship>";
               requestMain += "                <a:CanBeChanged>false</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>canbeprimaryentityinrelationship</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:CanBePrimaryEntityInRelationship>";
               requestMain += "              <c:CanBeRelatedEntityInRelationship>";
               requestMain += "                <a:CanBeChanged>false</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>canberelatedentityinrelationship</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:CanBeRelatedEntityInRelationship>";
               requestMain += "              <c:CanCreateAttributes>";
               requestMain += "                <a:CanBeChanged>false</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>cancreateattributes</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:CanCreateAttributes>";
               requestMain += "              <c:CanCreateCharts>";
               requestMain += "                <a:CanBeChanged>false</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>cancreatecharts</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:CanCreateCharts>";
               requestMain += "              <c:CanCreateForms>";
               requestMain += "                <a:CanBeChanged>false</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>cancreateforms</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:CanCreateForms>";
               requestMain += "              <c:CanCreateViews>";
               requestMain += "                <a:CanBeChanged>false</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>cancreateviews</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:CanCreateViews>";
               requestMain += "              <c:CanModifyAdditionalSettings>";
               requestMain += "                <a:CanBeChanged>true</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>canmodifyadditionalsettings</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:CanModifyAdditionalSettings>";
               requestMain += "              <c:CanTriggerWorkflow>true</c:CanTriggerWorkflow>";
               requestMain += "              <c:Description>";
               requestMain += "                <a:LocalizedLabels>";
               requestMain += "                  <a:LocalizedLabel>";
               requestMain += "                    <a:IsManaged i:nil=\"true\" />";
               requestMain += "                    <a:Label>my test description</a:Label>";
               requestMain += "                    <a:LanguageCode>1033</a:LanguageCode>";
               requestMain += "                  </a:LocalizedLabel>";
               requestMain += "                </a:LocalizedLabels>";
               requestMain += "                <a:UserLocalizedLabel i:nil=\"true\" />";
               requestMain += "              </c:Description>";
               requestMain += "              <c:DisplayCollectionName>";
               requestMain += "                <a:LocalizedLabels>";
               requestMain += "                  <a:LocalizedLabel>";
               requestMain += "                    <a:IsManaged>true</a:IsManaged>";
               requestMain += "                    <a:Label>Accounts</a:Label>";
               requestMain += "                    <a:LanguageCode>1033</a:LanguageCode>";
               requestMain += "                  </a:LocalizedLabel>";
               requestMain += "                </a:LocalizedLabels>";
               requestMain += "                <a:UserLocalizedLabel>";
               requestMain += "                  <a:IsManaged>true</a:IsManaged>";
               requestMain += "                  <a:Label>Accounts</a:Label>";
               requestMain += "                  <a:LanguageCode>1033</a:LanguageCode>";
               requestMain += "                </a:UserLocalizedLabel>";
               requestMain += "              </c:DisplayCollectionName>";
               requestMain += "              <c:DisplayName>";
               requestMain += "                <a:LocalizedLabels>";
               requestMain += "                  <a:LocalizedLabel>";
               requestMain += "                    <a:IsManaged>true</a:IsManaged>";
               requestMain += "                    <a:Label>Account</a:Label>";
               requestMain += "                    <a:LanguageCode>1033</a:LanguageCode>";
               requestMain += "                  </a:LocalizedLabel>";
               requestMain += "                </a:LocalizedLabels>";
               requestMain += "                <a:UserLocalizedLabel>";
               requestMain += "                  <a:IsManaged>true</a:IsManaged>";
               requestMain += "                  <a:Label>Account</a:Label>";
               requestMain += "                  <a:LanguageCode>1033</a:LanguageCode>";
               requestMain += "                </a:UserLocalizedLabel>";
               requestMain += "              </c:DisplayName>";
               requestMain += "              <c:IconLargeName i:nil=\"true\" />";
               requestMain += "              <c:IconMediumName i:nil=\"true\" />";
               requestMain += "              <c:IconSmallName i:nil=\"true\" />";
               requestMain += "              <c:IsActivity>false</c:IsActivity>";
               requestMain += "              <c:IsActivityParty>true</c:IsActivityParty>";
               requestMain += "              <c:IsAuditEnabled>";
               requestMain += "                <a:CanBeChanged>true</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>canmodifyauditsettings</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>false</a:Value>";
               requestMain += "              </c:IsAuditEnabled>";
               requestMain += "              <c:IsAvailableOffline>true</c:IsAvailableOffline>";
               requestMain += "              <c:IsChildEntity>false</c:IsChildEntity>";
               requestMain += "              <c:IsConnectionsEnabled>";
               requestMain += "                <a:CanBeChanged>true</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>canmodifyconnectionsettings</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:IsConnectionsEnabled>";
               requestMain += "              <c:IsCustomEntity>false</c:IsCustomEntity>";
               requestMain += "              <c:IsCustomizable>";
               requestMain += "                <a:CanBeChanged>false</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>iscustomizable</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:IsCustomizable>";
               requestMain += "              <c:IsDocumentManagementEnabled>true</c:IsDocumentManagementEnabled>";
               requestMain += "              <c:IsDuplicateDetectionEnabled>";
               requestMain += "                <a:CanBeChanged>true</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>canmodifyduplicatedetectionsettings</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:IsDuplicateDetectionEnabled>";
               requestMain += "              <c:IsEnabledForCharts>true</c:IsEnabledForCharts>";
               requestMain += "              <c:IsImportable>true</c:IsImportable>";
               requestMain += "              <c:IsIntersect>false</c:IsIntersect>";
               requestMain += "              <c:IsMailMergeEnabled>";
               requestMain += "                <a:CanBeChanged>true</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>canmodifymailmergesettings</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:IsMailMergeEnabled>";
               requestMain += "              <c:IsManaged>true</c:IsManaged>";
               requestMain += "              <c:IsMappable>";
               requestMain += "                <a:CanBeChanged>false</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>ismappable</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:IsMappable>";
               requestMain += "              <c:IsReadingPaneEnabled>true</c:IsReadingPaneEnabled>";
               requestMain += "              <c:IsRenameable>";
               requestMain += "                <a:CanBeChanged>false</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>isrenameable</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:IsRenameable>";
               requestMain += "              <c:IsValidForAdvancedFind>true</c:IsValidForAdvancedFind>";
               requestMain += "              <c:IsValidForQueue>";
               requestMain += "                <a:CanBeChanged>true</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>canmodifyqueuesettings</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>false</a:Value>";
               requestMain += "              </c:IsValidForQueue>";
               requestMain += "              <c:IsVisibleInMobile>";
               requestMain += "                <a:CanBeChanged>true</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName>canmodifymobilevisibility</a:ManagedPropertyLogicalName>";
               requestMain += "                <a:Value>true</a:Value>";
               requestMain += "              </c:IsVisibleInMobile>";
               requestMain += "              <c:LogicalName>account</c:LogicalName>";
               requestMain += "              <c:ManyToManyRelationships i:nil=\"true\" />";
               requestMain += "              <c:ManyToOneRelationships i:nil=\"true\" />";
               requestMain += "              <c:ObjectTypeCode>1</c:ObjectTypeCode>";
               requestMain += "              <c:OneToManyRelationships i:nil=\"true\" />";
               requestMain += "              <c:OwnershipType>UserOwned</c:OwnershipType>";
               requestMain += "              <c:PrimaryIdAttribute>accountid</c:PrimaryIdAttribute>";
               requestMain += "              <c:PrimaryNameAttribute>name</c:PrimaryNameAttribute>";
               requestMain += "              <c:Privileges i:nil=\"true\" />";
               requestMain += "              <c:RecurrenceBaseEntityLogicalName i:nil=\"true\" />";
               requestMain += "              <c:ReportViewName>FilteredAccount</c:ReportViewName>";
               requestMain += "              <c:SchemaName>Account</c:SchemaName>";
               requestMain += "            </b:value>";
               requestMain += "          </a:KeyValuePairOfstringanyType>";
               requestMain += "          <a:KeyValuePairOfstringanyType>";
               requestMain += "            <b:key>MergeLabels</b:key>";
               requestMain += "            <b:value i:type=\"c:boolean\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">false</b:value>";
               requestMain += "          </a:KeyValuePairOfstringanyType>";
               requestMain += "        </a:Parameters>";
               requestMain += "        <a:RequestId i:nil=\"true\" />";
               requestMain += "        <a:RequestName>UpdateEntity</a:RequestName>";
               requestMain += "      </request>";
               requestMain += "    </Execute>";
               requestMain += "  </s:Body>";
               requestMain += "</s:Envelope>";
               var req = new XMLHttpRequest();
               req.open("POST", SDK.SAMPLES._getServerUrl(), true)
               // Responses will return XML. It isn't possible to return JSON.
               req.setRequestHeader("Accept", "application/xml, text/xml, */*");
               req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
               req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
               var successCallback = null;
               var errorCallback = null;
               req.onreadystatechange = function () { SDK.SAMPLES.UpdateEntityResponse(req, successCallback, errorCallback); };
               req.send(requestMain);
           },
       UpdateEntityResponse: function (req, successCallback, errorCallback) {
               ///<summary>
               /// Recieves the assign response
               ///</summary>
               ///<param name="req" Type="XMLHttpRequest">
               /// The XMLHttpRequest response
               ///</param>
               ///<param name="successCallback" Type="Function">
               /// The function to perform when an successfult response is returned.
               /// For this message no data is returned so a success callback is not really necessary.
               ///</param>
               ///<param name="errorCallback" Type="Function">
               /// The function to perform when an error is returned.
               /// This function accepts a JScript error returned by the _getError function
               ///</param>
               if (req.readyState == 4) {
               if (req.status == 200) {
               if (successCallback != null)
               { successCallback(); }
               }
               else {
                   errorCallback(SDK.SAMPLES._getError(req.responseXML));
               }
           }
       },
       _getError: function (faultXml) {
           ///<summary>
           /// Parses the WCF fault returned in the event of an error.
           ///</summary>
           ///<param name="faultXml" Type="XML">
           /// The responseXML property of the XMLHttpRequest response.
           ///</param>
           var errorMessage = "Unknown Error (Unable to parse the fault)";
           if (typeof faultXml == "object") {
               try {
                   var bodyNode = faultXml.firstChild.firstChild;
                   //Retrieve the fault node
                   for (var i = 0; i < bodyNode.childNodes.length; i++) {
                       var node = bodyNode.childNodes[i];
                       //NOTE: This comparison does not handle the case where the XML namespace changes
                       if ("s:Fault" == node.nodeName) {
                       for (var j = 0; j < node.childNodes.length; j++) {
                           var faultStringNode = node.childNodes[j];
                           if ("faultstring" == faultStringNode.nodeName) {
                               errorMessage = faultStringNode.text;
                               break;
                           }
                       }
                       break;
                   }
               }
           }
           catch (e) { };
        }
        return new Error(errorMessage);
     },
 __namespace: true
};




To understand how to parse the response please review my post on using the DOM parser.
Now you can call the SDK.SAMPLES.UpdateEntityRequest function from your form jscript handler.
Thats all there is to it!

I hope this helps!

Tuesday, July 26, 2011

Determine if an Entity is Eligible to Participate in a Relationship Type Using Jscript or .NET in Microsoft Dynamics CRM 2011

This illustration shows how to programmatically determine if an entity is eligible to participate in a relationship typ  in Microsoft Dynamics CRM 2011 in code using jscript and also C#  with the RetrieveTimestampRequest.   This example will be given in SOAP (JScript) and in C# (.NET).

There are three different SDK web service messages highlighted in this post.  They are:

  • GetValidManyToManyRequest: Get list of entities that can participate in many to many relationships
  • GetValidReferencedEntitiesRequest: Get list of entities that can particaipate in one to many relationships as the "many" entity
  • GetValidReferencingEntitiesRequest: Get list of entities that can particaipate in one to many relationships as the "one" entity

Ok, here is what the code looks like!
First in C#:

GetValidManyToManyRequest req = new GetValidManyToManyRequest();

GetValidManyToManyResponse resp = (GetValidManyToManyResponse)service.Execute(req);


//Get list of entities that can particaipate in one to many relationships as the "many" entity
GetValidReferencedEntitiesRequest req2 = new GetValidReferencedEntitiesRequest();

GetValidReferencedEntitiesResponse resp2 = (GetValidReferencedEntitiesResponse)service.Execute(req2);


//Get list of entities that can particaipate in one to many relationships as the "one" entity
GetValidReferencingEntitiesRequest req3 = new GetValidReferencingEntitiesRequest();

GetValidReferencingEntitiesResponse resp3 = (GetValidReferencingEntitiesResponse)service.Execute(req3);

//now you can get the entitie names this way for each response
//string[] strEntityNames = resp.EntityNames;


If you need help instantiating a service object in .NET within a plugin check out this post:
http://mileyja.blogspot.com/2011/04/instantiating-service-object-within.html

Now here is the Jscript nicely formatted by the CRM 2011 SOAP formatter. Available at: http://crm2011soap.codeplex.com/

Now in Jscript, in three separate blocks (one for each call)


This example is asynchronous, if you want to learn how to make JScript SOAP calls synchronously please visit this post: http://mileyja.blogspot.com/2011/07/using-jscript-to-access-soap-web.html


if (typeof (SDK) == "undefined")
   { SDK = { __namespace: true }; }
       //This will establish a more unique namespace for functions in this library. This will reduce the 
       // potential for functions to be overwritten due to a duplicate name when the library is loaded.
       SDK.SAMPLES = {
           _getServerUrl: function () {
               ///<summary>
               /// Returns the URL for the SOAP endpoint using the context information available in the form
               /// or HTML Web resource.
               ///</summary>
               var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
               var serverUrl = "";
               if (typeof GetGlobalContext == "function") {
                   var context = GetGlobalContext();
                   serverUrl = context.getServerUrl();
               }
               else {
                   if (typeof Xrm.Page.context == "object") {
                         serverUrl = Xrm.Page.context.getServerUrl();
                   }
                   else
                   { throw new Error("Unable to access the server URL"); }
                   }
                  if (serverUrl.match(/\/$/)) {
                       serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                   } 
                   return serverUrl + OrgServicePath;
               }, 
           GetValidManyToManyRequest: function () {
               var requestMain = ""
               requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
               requestMain += "  <s:Body>";
               requestMain += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
               requestMain += "      <request i:type=\"a:GetValidManyToManyRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
               requestMain += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\" />";
               requestMain += "        <a:RequestId i:nil=\"true\" />";
               requestMain += "        <a:RequestName>GetValidManyToMany</a:RequestName>";
               requestMain += "      </request>";
               requestMain += "    </Execute>";
               requestMain += "  </s:Body>";
               requestMain += "</s:Envelope>";
               var req = new XMLHttpRequest();
               req.open("POST", SDK.SAMPLES._getServerUrl(), true)
               // Responses will return XML. It isn't possible to return JSON.
               req.setRequestHeader("Accept", "application/xml, text/xml, */*");
               req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
               req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
               var successCallback = null;
               var errorCallback = null;
               req.onreadystatechange = function () { SDK.SAMPLES.GetValidManyToManyResponse(req, successCallback, errorCallback); };
               req.send(requestMain);
           },
       GetValidManyToManyResponse: function (req, successCallback, errorCallback) {
               ///<summary>
               /// Recieves the assign response
               ///</summary>
               ///<param name="req" Type="XMLHttpRequest">
               /// The XMLHttpRequest response
               ///</param>
               ///<param name="successCallback" Type="Function">
               /// The function to perform when an successfult response is returned.
               /// For this message no data is returned so a success callback is not really necessary.
               ///</param>
               ///<param name="errorCallback" Type="Function">
               /// The function to perform when an error is returned.
               /// This function accepts a JScript error returned by the _getError function
               ///</param>
               if (req.readyState == 4) {
               if (req.status == 200) {
               if (successCallback != null)
               { successCallback(); }
               }
               else {
                   errorCallback(SDK.SAMPLES._getError(req.responseXML));
               }
           }
       },
       _getError: function (faultXml) {
           ///<summary>
           /// Parses the WCF fault returned in the event of an error.
           ///</summary>
           ///<param name="faultXml" Type="XML">
           /// The responseXML property of the XMLHttpRequest response.
           ///</param>
           var errorMessage = "Unknown Error (Unable to parse the fault)";
           if (typeof faultXml == "object") {
               try {
                   var bodyNode = faultXml.firstChild.firstChild;
                   //Retrieve the fault node
                   for (var i = 0; i < bodyNode.childNodes.length; i++) {
                       var node = bodyNode.childNodes[i];
                       //NOTE: This comparison does not handle the case where the XML namespace changes
                       if ("s:Fault" == node.nodeName) {
                       for (var j = 0; j < node.childNodes.length; j++) {
                           var faultStringNode = node.childNodes[j];
                           if ("faultstring" == faultStringNode.nodeName) {
                               errorMessage = faultStringNode.text;
                               break;
                           }
                       }
                       break;
                   }
               }
           }
           catch (e) { };
        }
        return new Error(errorMessage);
     },
 __namespace: true
};



if (typeof (SDK) == "undefined")
   { SDK = { __namespace: true }; }
       //This will establish a more unique namespace for functions in this library. This will reduce the 
       // potential for functions to be overwritten due to a duplicate name when the library is loaded.
       SDK.SAMPLES = {
           _getServerUrl: function () {
               ///<summary>
               /// Returns the URL for the SOAP endpoint using the context information available in the form
               /// or HTML Web resource.
               ///</summary>
               var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
               var serverUrl = "";
               if (typeof GetGlobalContext == "function") {
                   var context = GetGlobalContext();
                   serverUrl = context.getServerUrl();
               }
               else {
                   if (typeof Xrm.Page.context == "object") {
                         serverUrl = Xrm.Page.context.getServerUrl();
                   }
                   else
                   { throw new Error("Unable to access the server URL"); }
                   }
                  if (serverUrl.match(/\/$/)) {
                       serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                   } 
                   return serverUrl + OrgServicePath;
               }, 
           GetValidReferencedEntitiesRequest: function () {
               var requestMain = ""
               requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
               requestMain += "  <s:Body>";
               requestMain += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
               requestMain += "      <request i:type=\"a:GetValidReferencedEntitiesRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
               requestMain += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\" />";
               requestMain += "        <a:RequestId i:nil=\"true\" />";
               requestMain += "        <a:RequestName>GetValidReferencedEntities</a:RequestName>";
               requestMain += "      </request>";
               requestMain += "    </Execute>";
               requestMain += "  </s:Body>";
               requestMain += "</s:Envelope>";
               var req = new XMLHttpRequest();
               req.open("POST", SDK.SAMPLES._getServerUrl(), true)
               // Responses will return XML. It isn't possible to return JSON.
               req.setRequestHeader("Accept", "application/xml, text/xml, */*");
               req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
               req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
               var successCallback = null;
               var errorCallback = null;
               req.onreadystatechange = function () { SDK.SAMPLES.GetValidReferencedEntitiesResponse(req, successCallback, errorCallback); };
               req.send(requestMain);
           },
       GetValidReferencedEntitiesResponse: function (req, successCallback, errorCallback) {
               ///<summary>
               /// Recieves the assign response
               ///</summary>
               ///<param name="req" Type="XMLHttpRequest">
               /// The XMLHttpRequest response
               ///</param>
               ///<param name="successCallback" Type="Function">
               /// The function to perform when an successfult response is returned.
               /// For this message no data is returned so a success callback is not really necessary.
               ///</param>
               ///<param name="errorCallback" Type="Function">
               /// The function to perform when an error is returned.
               /// This function accepts a JScript error returned by the _getError function
               ///</param>
               if (req.readyState == 4) {
               if (req.status == 200) {
               if (successCallback != null)
               { successCallback(); }
               }
               else {
                   errorCallback(SDK.SAMPLES._getError(req.responseXML));
               }
           }
       },
       _getError: function (faultXml) {
           ///<summary>
           /// Parses the WCF fault returned in the event of an error.
           ///</summary>
           ///<param name="faultXml" Type="XML">
           /// The responseXML property of the XMLHttpRequest response.
           ///</param>
           var errorMessage = "Unknown Error (Unable to parse the fault)";
           if (typeof faultXml == "object") {
               try {
                   var bodyNode = faultXml.firstChild.firstChild;
                   //Retrieve the fault node
                   for (var i = 0; i < bodyNode.childNodes.length; i++) {
                       var node = bodyNode.childNodes[i];
                       //NOTE: This comparison does not handle the case where the XML namespace changes
                       if ("s:Fault" == node.nodeName) {
                       for (var j = 0; j < node.childNodes.length; j++) {
                           var faultStringNode = node.childNodes[j];
                           if ("faultstring" == faultStringNode.nodeName) {
                               errorMessage = faultStringNode.text;
                               break;
                           }
                       }
                       break;
                   }
               }
           }
           catch (e) { };
        }
        return new Error(errorMessage);
     },
 __namespace: true
};



if (typeof (SDK) == "undefined")
   { SDK = { __namespace: true }; }
       //This will establish a more unique namespace for functions in this library. This will reduce the 
       // potential for functions to be overwritten due to a duplicate name when the library is loaded.
       SDK.SAMPLES = {
           _getServerUrl: function () {
               ///<summary>
               /// Returns the URL for the SOAP endpoint using the context information available in the form
               /// or HTML Web resource.
               ///</summary>
               var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
               var serverUrl = "";
               if (typeof GetGlobalContext == "function") {
                   var context = GetGlobalContext();
                   serverUrl = context.getServerUrl();
               }
               else {
                   if (typeof Xrm.Page.context == "object") {
                         serverUrl = Xrm.Page.context.getServerUrl();
                   }
                   else
                   { throw new Error("Unable to access the server URL"); }
                   }
                  if (serverUrl.match(/\/$/)) {
                       serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                   } 
                   return serverUrl + OrgServicePath;
               }, 
           GetValidReferencingEntitiesRequest: function () {
               var requestMain = ""
               requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
               requestMain += "  <s:Body>";
               requestMain += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
               requestMain += "      <request i:type=\"a:GetValidReferencingEntitiesRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
               requestMain += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\" />";
               requestMain += "        <a:RequestId i:nil=\"true\" />";
               requestMain += "        <a:RequestName>GetValidReferencingEntities</a:RequestName>";
               requestMain += "      </request>";
               requestMain += "    </Execute>";
               requestMain += "  </s:Body>";
               requestMain += "</s:Envelope>";
               var req = new XMLHttpRequest();
               req.open("POST", SDK.SAMPLES._getServerUrl(), true)
               // Responses will return XML. It isn't possible to return JSON.
               req.setRequestHeader("Accept", "application/xml, text/xml, */*");
               req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
               req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
               var successCallback = null;
               var errorCallback = null;
               req.onreadystatechange = function () { SDK.SAMPLES.GetValidReferencingEntitiesResponse(req, successCallback, errorCallback); };
               req.send(requestMain);
           },
       GetValidReferencingEntitiesResponse: function (req, successCallback, errorCallback) {
               ///<summary>
               /// Recieves the assign response
               ///</summary>
               ///<param name="req" Type="XMLHttpRequest">
               /// The XMLHttpRequest response
               ///</param>
               ///<param name="successCallback" Type="Function">
               /// The function to perform when an successfult response is returned.
               /// For this message no data is returned so a success callback is not really necessary.
               ///</param>
               ///<param name="errorCallback" Type="Function">
               /// The function to perform when an error is returned.
               /// This function accepts a JScript error returned by the _getError function
               ///</param>
               if (req.readyState == 4) {
               if (req.status == 200) {
               if (successCallback != null)
               { successCallback(); }
               }
               else {
                   errorCallback(SDK.SAMPLES._getError(req.responseXML));
               }
           }
       },
       _getError: function (faultXml) {
           ///<summary>
           /// Parses the WCF fault returned in the event of an error.
           ///</summary>
           ///<param name="faultXml" Type="XML">
           /// The responseXML property of the XMLHttpRequest response.
           ///</param>
           var errorMessage = "Unknown Error (Unable to parse the fault)";
           if (typeof faultXml == "object") {
               try {
                   var bodyNode = faultXml.firstChild.firstChild;
                   //Retrieve the fault node
                   for (var i = 0; i < bodyNode.childNodes.length; i++) {
                       var node = bodyNode.childNodes[i];
                       //NOTE: This comparison does not handle the case where the XML namespace changes
                       if ("s:Fault" == node.nodeName) {
                       for (var j = 0; j < node.childNodes.length; j++) {
                           var faultStringNode = node.childNodes[j];
                           if ("faultstring" == faultStringNode.nodeName) {
                               errorMessage = faultStringNode.text;
                               break;
                           }
                       }
                       break;
                   }
               }
           }
           catch (e) { };
        }
        return new Error(errorMessage);
     },
 __namespace: true
};




To understand how to parse the response please review my post on using the DOM parser.
Now you can call SDK.SAMPLES.GetValidManyToManyRequest, SDK.SAMPLES.GetValidReferencedEntitiesRequest, or SDK.SAMPLES.GetValidReferencingEntitiesRequest respectively to use each call in Jscript on your CRM form.
Thats all there is to it!

I hope this helps!

Monday, July 25, 2011

Determine if Metadata has Changed Using Jscript or C# in Microsoft Dynamics CRM 2011 Using RetrieveTimestampRequest

This illustration shows how to programmatically determine if there have been changes in Metadata  in Microsoft Dynamics CRM 2011 in code using jscript and also C#  with the RetrieveTimestampRequest.   This example will be given in SOAP (JScript) and in C# (.NET).

IMPORTANT NOTE: The time stamp retrieved is actually not a time stamp at all.  It's really a hash computed on the metadata in CRM.   This means that you must have a previous time stamp value to compare against to be able to determine if a change has occurred or not.

Ok, here is what the code look like!
First in C#:

RetrieveTimestampRequest req = new RetrieveTimestampRequest();
RetrieveTimestampResponse resp = (RetrieveTimestampResponse)slos.Execute(req);


If you need help instantiating a service object in .NET within a plugin check out this post:
http://mileyja.blogspot.com/2011/04/instantiating-service-object-within.html

Now here is the Jscript nicely formatted by the CRM 2011 SOAP formatter. Available at: http://crm2011soap.codeplex.com/

Now in Jscript


This is example is asynchronous, if you want to learn how to make JScript SOAP calls synchronously please visit this post: http://mileyja.blogspot.com/2011/07/using-jscript-to-access-soap-web.html


if (typeof (SDK) == "undefined")
   { SDK = { __namespace: true }; }
       //This will establish a more unique namespace for functions in this library. This will reduce the 
       // potential for functions to be overwritten due to a duplicate name when the library is loaded.
       SDK.SAMPLES = {
           _getServerUrl: function () {
               ///<summary>
               /// Returns the URL for the SOAP endpoint using the context information available in the form
               /// or HTML Web resource.
               ///</summary>
               var ServicePath = "/XRMServices/2011/Organization.svc/web";
               var serverUrl = "";
               if (typeof GetGlobalContext == "function") {
                   var context = GetGlobalContext();
                   serverUrl = context.getServerUrl();
               }
               else {
                   if (typeof Xrm.Page.context == "object") {
                         serverUrl = Xrm.Page.context.getServerUrl();
                   }
                   else
                   { throw new Error("Unable to access the server URL"); }
                   }
                  if (serverUrl.match(/\/$/)) {
                       serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                   } 
                   return serverUrl + ServicePath;
               }, 
           RetrieveTimestampRequest: function () {
               var requestMain = ""
               requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
               requestMain += "  <s:Body>";
               requestMain += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
               requestMain += "      <request i:type=\"a:RetrieveTimestampRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
               requestMain += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\" />";
               requestMain += "        <a:RequestId i:nil=\"true\" />";
               requestMain += "        <a:RequestName>RetrieveTimestamp</a:RequestName>";
               requestMain += "      </request>";
               requestMain += "    </Execute>";
               requestMain += "  </s:Body>";
               requestMain += "</s:Envelope>";
               var req = new XMLHttpRequest();
               req.open("POST", SDK.SAMPLES._getServerUrl(), true)
               req.setRequestHeader("Accept", "application/xml, text/xml, */*");
               req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
               req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
               var successCallback = null;
               var errorCallback = null;
               req.onreadystatechange = function () { SDK.SAMPLES.RetrieveTimestampResponse(req, successCallback, errorCallback); };
               req.send(requestMain);
           },
       RetrieveTimestampResponse: function (req, successCallback, errorCallback) {
               ///<summary>
               /// Recieves the assign response
               ///</summary>
               ///<param name="req" Type="XMLHttpRequest">
               /// The XMLHttpRequest response
               ///</param>
               ///<param name="successCallback" Type="Function">
               /// The function to perform when an successfult response is returned.
               /// For this message no data is returned so a success callback is not really necessary.
               ///</param>
               ///<param name="errorCallback" Type="Function">
               /// The function to perform when an error is returned.
               /// This function accepts a JScript error returned by the _getError function
               ///</param>
               if (req.readyState == 4) {
               if (req.status == 200) {
               if (successCallback != null)
               { successCallback(); }
               }
               else {
                   errorCallback(SDK.SAMPLES._getError(req.responseXML));
               }
           }
       },
       _getError: function (faultXml) {
           ///<summary>
           /// Parses the WCF fault returned in the event of an error.
           ///</summary>
           ///<param name="faultXml" Type="XML">
           /// The responseXML property of the XMLHttpRequest response.
           ///</param>
           var errorMessage = "Unknown Error (Unable to parse the fault)";
           if (typeof faultXml == "object") {
               try {
                   var bodyNode = faultXml.firstChild.firstChild;
                   //Retrieve the fault node
                   for (var i = 0; i < bodyNode.childNodes.length; i++) {
                       var node = bodyNode.childNodes[i];
                       //NOTE: This comparison does not handle the case where the XML namespace changes
                       if ("s:Fault" == node.nodeName) {
                       for (var j = 0; j < node.childNodes.length; j++) {
                           var faultStringNode = node.childNodes[j];
                           if ("faultstring" == faultStringNode.nodeName) {
                               errorMessage = faultStringNode.text;
                               break;
                           }
                       }
                       break;
                   }
               }
           }
           catch (e) { };
        }
        return new Error(errorMessage);
     },
 __namespace: true
};




To understand how to parse the response please review my post on using the DOM parser.
Now you can call the SDK.SAMPLES.RetrieveTimestampRequest function from your form jscript handler.
Thats all there is to it!

I hope this helps!

Sunday, July 24, 2011

Another Great Article on Setting Up Claims-Based IFD For CRM 2011

In reply to one of my previous posts, Interactivewebs replied and mentioned his post on this topic. I took a quick look and it looks really complete and like a pretty nice tutorial.

http://www.interactivewebs.com/blog/index.php/server-tips/microsoft-crm-2011-how-to-configure-ifd-hosted-setup/

Thanks for this.

- I hope this helps!

Friday, July 22, 2011

Create a Many-To-Many Relationship with Jscript or .Net in Microsoft Dynamics CRM 2011 With CreateManyToManyRequest

This illustration shows how to create a many-to-many relationship between two entities in Microsoft Dynamics CRM 2011 in code in jscript and also C#  using the CreateManyToManyRequest.   This example will be given in SOAP (JScript) and in C# (.NET).

Ok, here is what the code look like!
First in C#:

CreateManyToManyRequest createManyToManyRelationshipRequest =
new CreateManyToManyRequest
{
    IntersectEntitySchemaName = "new_accounts_campaigns",
    ManyToManyRelationship = new ManyToManyRelationshipMetadata
    {
        SchemaName = "new_accounts_campaigns",
        Entity1LogicalName = "account",
        Entity1AssociatedMenuConfiguration =
        new AssociatedMenuConfiguration
        {
            Behavior = AssociatedMenuBehavior.UseLabel,
            Group = AssociatedMenuGroup.Details,
            Label = new Label("Account", 1033),
            Order = 10000
        },
        Entity2LogicalName = "campaign",
        Entity2AssociatedMenuConfiguration =
        new AssociatedMenuConfiguration
        {
            Behavior = AssociatedMenuBehavior.UseLabel,
            Group = AssociatedMenuGroup.Details,
            Label = new Label("Campaign", 1033),
            Order = 10000
        }
    }
};

CreateManyToManyResponse createManytoManyRelationshipResponse =
    (CreateManyToManyResponse)slos.Execute(
    createManyToManyRelationshipRequest);

//here are some examples of how to work with the response

//_manyToManyRelationshipId =
//    createManytoManyRelationshipResponse.ManyToManyRelationshipId;
//_manyToManyRelationshipName =
//    createManyToManyRelationshipRequest.ManyToManyRelationship.SchemaName;

If you need help instantiating a service object in .NET within a plugin check out this post:
http://mileyja.blogspot.com/2011/04/instantiating-service-object-within.html

Now here is the Jscript nicely formatted by the CRM 2011 SOAP formatter. Available at: http://crm2011soap.codeplex.com/

Now in Jscript


This is example is asynchronous, if you want to learn how to make JScript SOAP calls synchronously please visit this post: http://mileyja.blogspot.com/2011/07/using-jscript-to-access-soap-web.html

if (typeof (SDK) == "undefined")
   { SDK = { __namespace: true }; }
       //This will establish a more unique namespace for functions in this library. This will reduce the 
       // potential for functions to be overwritten due to a duplicate name when the library is loaded.
       SDK.SAMPLES = {
           _getServerUrl: function () {
               ///<summary>
               /// Returns the URL for the SOAP endpoint using the context information available in the form
               /// or HTML Web resource.
               ///</summary>
               var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
               var serverUrl = "";
               if (typeof GetGlobalContext == "function") {
                   var context = GetGlobalContext();
                   serverUrl = context.getServerUrl();
               }
               else {
                   if (typeof Xrm.Page.context == "object") {
                         serverUrl = Xrm.Page.context.getServerUrl();
                   }
                   else
                   { throw new Error("Unable to access the server URL"); }
                   }
                  if (serverUrl.match(/\/$/)) {
                       serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                   } 
                   return serverUrl + OrgServicePath;
               }, 
           CreateManyToManyRequest: function () {
               var requestMain = ""
               requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
               requestMain += "  <s:Body>";
               requestMain += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
               requestMain += "      <request i:type=\"a:CreateManyToManyRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
               requestMain += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
               requestMain += "          <a:KeyValuePairOfstringanyType>";
               requestMain += "            <b:key>IntersectEntitySchemaName</b:key>";
               requestMain += "            <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">new_accounts_campaigns</b:value>";
               requestMain += "          </a:KeyValuePairOfstringanyType>";
               requestMain += "          <a:KeyValuePairOfstringanyType>";
               requestMain += "            <b:key>ManyToManyRelationship</b:key>";
               requestMain += "            <b:value i:type=\"c:ManyToManyRelationshipMetadata\" xmlns:c=\"http://schemas.microsoft.com/xrm/2011/Metadata\">";
               requestMain += "              <c:MetadataId i:nil=\"true\" />";
               requestMain += "              <c:IsCustomRelationship i:nil=\"true\" />";
               requestMain += "              <c:IsCustomizable i:nil=\"true\" />";
               requestMain += "              <c:IsManaged i:nil=\"true\" />";
               requestMain += "              <c:IsValidForAdvancedFind i:nil=\"true\" />";
               requestMain += "              <c:SchemaName>new_accounts_campaigns</c:SchemaName>";
               requestMain += "              <c:SecurityTypes i:nil=\"true\" />";
               requestMain += "              <c:Entity1AssociatedMenuConfiguration>";
               requestMain += "                <c:Behavior>UseLabel</c:Behavior>";
               requestMain += "                <c:Group>Details</c:Group>";
               requestMain += "                <c:Label>";
               requestMain += "                  <a:LocalizedLabels>";
               requestMain += "                    <a:LocalizedLabel>";
               requestMain += "                      <a:IsManaged i:nil=\"true\" />";
               requestMain += "                      <a:Label>Account</a:Label>";
               requestMain += "                      <a:LanguageCode>1033</a:LanguageCode>";
               requestMain += "                    </a:LocalizedLabel>";
               requestMain += "                  </a:LocalizedLabels>";
               requestMain += "                  <a:UserLocalizedLabel i:nil=\"true\" />";
               requestMain += "                </c:Label>";
               requestMain += "                <c:Order>10000</c:Order>";
               requestMain += "              </c:Entity1AssociatedMenuConfiguration>";
               requestMain += "              <c:Entity1IntersectAttribute i:nil=\"true\" />";
               requestMain += "              <c:Entity1LogicalName>account</c:Entity1LogicalName>";
               requestMain += "              <c:Entity2AssociatedMenuConfiguration>";
               requestMain += "                <c:Behavior>UseLabel</c:Behavior>";
               requestMain += "                <c:Group>Details</c:Group>";
               requestMain += "                <c:Label>";
               requestMain += "                  <a:LocalizedLabels>";
               requestMain += "                    <a:LocalizedLabel>";
               requestMain += "                      <a:IsManaged i:nil=\"true\" />";
               requestMain += "                      <a:Label>Campaign</a:Label>";
               requestMain += "                      <a:LanguageCode>1033</a:LanguageCode>";
               requestMain += "                    </a:LocalizedLabel>";
               requestMain += "                  </a:LocalizedLabels>";
               requestMain += "                  <a:UserLocalizedLabel i:nil=\"true\" />";
               requestMain += "                </c:Label>";
               requestMain += "                <c:Order>10000</c:Order>";
               requestMain += "              </c:Entity2AssociatedMenuConfiguration>";
               requestMain += "              <c:Entity2IntersectAttribute i:nil=\"true\" />";
               requestMain += "              <c:Entity2LogicalName>campaign</c:Entity2LogicalName>";
               requestMain += "              <c:IntersectEntityName i:nil=\"true\" />";
               requestMain += "            </b:value>";
               requestMain += "          </a:KeyValuePairOfstringanyType>";
               requestMain += "        </a:Parameters>";
               requestMain += "        <a:RequestId i:nil=\"true\" />";
               requestMain += "        <a:RequestName>CreateManyToMany</a:RequestName>";
               requestMain += "      </request>";
               requestMain += "    </Execute>";
               requestMain += "  </s:Body>";
               requestMain += "</s:Envelope>";
               var req = new XMLHttpRequest();
               req.open("POST", SDK.SAMPLES._getServerUrl(), true)
               // Responses will return XML. It isn't possible to return JSON.
               req.setRequestHeader("Accept", "application/xml, text/xml, */*");
               req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
               req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
               var successCallback = null;
               var errorCallback = null;
               req.onreadystatechange = function () { SDK.SAMPLES.CreateManyToManyResponse(req, successCallback, errorCallback); };
               req.send(requestMain);
           },
       CreateManyToManyResponse: function (req, successCallback, errorCallback) {
               ///<summary>
               /// Recieves the assign response
               ///</summary>
               ///<param name="req" Type="XMLHttpRequest">
               /// The XMLHttpRequest response
               ///</param>
               ///<param name="successCallback" Type="Function">
               /// The function to perform when an successfult response is returned.
               /// For this message no data is returned so a success callback is not really necessary.
               ///</param>
               ///<param name="errorCallback" Type="Function">
               /// The function to perform when an error is returned.
               /// This function accepts a JScript error returned by the _getError function
               ///</param>
               if (req.readyState == 4) {
               if (req.status == 200) {
               if (successCallback != null)
               { successCallback(); }
               }
               else {
                   errorCallback(SDK.SAMPLES._getError(req.responseXML));
               }
           }
       },
       _getError: function (faultXml) {
           ///<summary>
           /// Parses the WCF fault returned in the event of an error.
           ///</summary>
           ///<param name="faultXml" Type="XML">
           /// The responseXML property of the XMLHttpRequest response.
           ///</param>
           var errorMessage = "Unknown Error (Unable to parse the fault)";
           if (typeof faultXml == "object") {
               try {
                   var bodyNode = faultXml.firstChild.firstChild;
                   //Retrieve the fault node
                   for (var i = 0; i < bodyNode.childNodes.length; i++) {
                       var node = bodyNode.childNodes[i];
                       //NOTE: This comparison does not handle the case where the XML namespace changes
                       if ("s:Fault" == node.nodeName) {
                       for (var j = 0; j < node.childNodes.length; j++) {
                           var faultStringNode = node.childNodes[j];
                           if ("faultstring" == faultStringNode.nodeName) {
                               errorMessage = faultStringNode.text;
                               break;
                           }
                       }
                       break;
                   }
               }
           }
           catch (e) { };
        }
        return new Error(errorMessage);
     },
 __namespace: true
};




To understand how to parse the response please review my post on using the DOM parser.
Now you can call the SDK.SAMPLES.CreateManyToManyRequest function from your form jscript handler.
Thats all there is to it!

I hope this helps!

Thursday, July 21, 2011

Create a One-To-Many Relationship with Jscript or .Net in Microsoft Dynamics CRM 2011 With CreateOneToManyRequest

This illustration shows how to create a one-to-many relationship between two entities in Microsoft Dynamics CRM 2011 in code in jscript and also C#  using the CreateOneToManyRequest.   This example will be given in SOAP (JScript) and in C# (.NET).

Ok, here is what the code look like!
First in C#:

 CreateOneToManyRequest req =
         new CreateOneToManyRequest
    {
        OneToManyRelationship =
        new OneToManyRelationshipMetadata
        {
            ReferencedEntity = "account",
            ReferencingEntity = "campaign",
            SchemaName = "new_account_campaign",
            AssociatedMenuConfiguration = new AssociatedMenuConfiguration
            {
                Behavior = AssociatedMenuBehavior.UseLabel,
                Group = AssociatedMenuGroup.Details,
                Label = new Label("Account", 1033),
                Order = 10000
            },
            CascadeConfiguration = new CascadeConfiguration
            {
                Assign = CascadeType.Cascade,
                Delete = CascadeType.Cascade,
                Merge = CascadeType.Cascade,
                Reparent = CascadeType.Cascade,
                Share = CascadeType.Cascade,
                Unshare = CascadeType.Cascade
            }
        },
        Lookup = new LookupAttributeMetadata
        {
            SchemaName = "new_parent_accountid",
            DisplayName = new Label("Account Lookup", 1033),
            RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
            Description = new Label("Sample Lookup", 1033)
        }
    };


CreateOneToManyResponse resp =
    (CreateOneToManyResponse)slos.Execute(
    req);

//now you can work with the relationship values that come back.    

//_oneToManyRelationshipId =
//    createOneToManyRelationshipResponse.RelationshipId;
//_oneToManyRelationshipName =
//    createOneToManyRelationshipRequest.OneToManyRelationship.SchemaName;

If you need help instantiating a service object in .NET within a plugin check out this post:
http://mileyja.blogspot.com/2011/04/instantiating-service-object-within.html

Now here is the Jscript nicely formatted by the CRM 2011 SOAP formatter. Available at: http://crm2011soap.codeplex.com/

Now in JSCRIPT:


This is example is asynchronous, if you want to learn how to make JScript SOAP calls synchronously please visit this post: http://mileyja.blogspot.com/2011/07/using-jscript-to-access-soap-web.html

if (typeof (SDK) == "undefined")
   { SDK = { __namespace: true }; }
       //This will establish a more unique namespace for functions in this library. This will reduce the 
       // potential for functions to be overwritten due to a duplicate name when the library is loaded.
       SDK.SAMPLES = {
           _getServerUrl: function () {
               ///<summary>
               /// Returns the URL for the SOAP endpoint using the context information available in the form
               /// or HTML Web resource.
               ///</summary>
               var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
               var serverUrl = "";
               if (typeof GetGlobalContext == "function") {
                   var context = GetGlobalContext();
                   serverUrl = context.getServerUrl();
               }
               else {
                   if (typeof Xrm.Page.context == "object") {
                         serverUrl = Xrm.Page.context.getServerUrl();
                   }
                   else
                   { throw new Error("Unable to access the server URL"); }
                   }
                  if (serverUrl.match(/\/$/)) {
                       serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                   } 
                   return serverUrl + OrgServicePath;
               }, 
           CreateOneToManyRequest: function () {
               var requestMain = ""
               requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
               requestMain += "  <s:Body>";
               requestMain += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
               requestMain += "      <request i:type=\"a:CreateOneToManyRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
               requestMain += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
               requestMain += "          <a:KeyValuePairOfstringanyType>";
               requestMain += "            <b:key>Lookup</b:key>";
               requestMain += "            <b:value i:type=\"c:LookupAttributeMetadata\" xmlns:c=\"http://schemas.microsoft.com/xrm/2011/Metadata\">";
               requestMain += "              <c:MetadataId i:nil=\"true\" />";
               requestMain += "              <c:AttributeOf i:nil=\"true\" />";
               requestMain += "              <c:AttributeType>Lookup</c:AttributeType>";
               requestMain += "              <c:CanBeSecuredForCreate i:nil=\"true\" />";
               requestMain += "              <c:CanBeSecuredForRead i:nil=\"true\" />";
               requestMain += "              <c:CanBeSecuredForUpdate i:nil=\"true\" />";
               requestMain += "              <c:CanModifyAdditionalSettings i:nil=\"true\" />";
               requestMain += "              <c:ColumnNumber i:nil=\"true\" />";
               requestMain += "              <c:DeprecatedVersion i:nil=\"true\" />";
               requestMain += "              <c:Description>";
               requestMain += "                <a:LocalizedLabels>";
               requestMain += "                  <a:LocalizedLabel>";
               requestMain += "                    <a:IsManaged i:nil=\"true\" />";
               requestMain += "                    <a:Label>Sample Lookup</a:Label>";
               requestMain += "                    <a:LanguageCode>1033</a:LanguageCode>";
               requestMain += "                  </a:LocalizedLabel>";
               requestMain += "                </a:LocalizedLabels>";
               requestMain += "                <a:UserLocalizedLabel i:nil=\"true\" />";
               requestMain += "              </c:Description>";
               requestMain += "              <c:DisplayName>";
               requestMain += "                <a:LocalizedLabels>";
               requestMain += "                  <a:LocalizedLabel>";
               requestMain += "                    <a:IsManaged i:nil=\"true\" />";
               requestMain += "                    <a:Label>Account Lookup</a:Label>";
               requestMain += "                    <a:LanguageCode>1033</a:LanguageCode>";
               requestMain += "                  </a:LocalizedLabel>";
               requestMain += "                </a:LocalizedLabels>";
               requestMain += "                <a:UserLocalizedLabel i:nil=\"true\" />";
               requestMain += "              </c:DisplayName>";
               requestMain += "              <c:EntityLogicalName i:nil=\"true\" />";
               requestMain += "              <c:IsAuditEnabled i:nil=\"true\" />";
               requestMain += "              <c:IsCustomAttribute i:nil=\"true\" />";
               requestMain += "              <c:IsCustomizable i:nil=\"true\" />";
               requestMain += "              <c:IsManaged i:nil=\"true\" />";
               requestMain += "              <c:IsPrimaryId i:nil=\"true\" />";
               requestMain += "              <c:IsPrimaryName i:nil=\"true\" />";
               requestMain += "              <c:IsRenameable i:nil=\"true\" />";
               requestMain += "              <c:IsSecured i:nil=\"true\" />";
               requestMain += "              <c:IsValidForAdvancedFind i:nil=\"true\" />";
               requestMain += "              <c:IsValidForCreate i:nil=\"true\" />";
               requestMain += "              <c:IsValidForRead i:nil=\"true\" />";
               requestMain += "              <c:IsValidForUpdate i:nil=\"true\" />";
               requestMain += "              <c:LinkedAttributeId i:nil=\"true\" />";
               requestMain += "              <c:LogicalName i:nil=\"true\" />";
               requestMain += "              <c:RequiredLevel>";
               requestMain += "                <a:CanBeChanged>true</a:CanBeChanged>";
               requestMain += "                <a:ManagedPropertyLogicalName i:nil=\"true\" />";
               requestMain += "                <a:Value>None</a:Value>";
               requestMain += "              </c:RequiredLevel>";
               requestMain += "              <c:SchemaName>new_parent_accountid</c:SchemaName>";
               requestMain += "              <c:Targets i:nil=\"true\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\" />";
               requestMain += "            </b:value>";
               requestMain += "          </a:KeyValuePairOfstringanyType>";
               requestMain += "          <a:KeyValuePairOfstringanyType>";
               requestMain += "            <b:key>OneToManyRelationship</b:key>";
               requestMain += "            <b:value i:type=\"c:OneToManyRelationshipMetadata\" xmlns:c=\"http://schemas.microsoft.com/xrm/2011/Metadata\">";
               requestMain += "              <c:MetadataId i:nil=\"true\" />";
               requestMain += "              <c:IsCustomRelationship i:nil=\"true\" />";
               requestMain += "              <c:IsCustomizable i:nil=\"true\" />";
               requestMain += "              <c:IsManaged i:nil=\"true\" />";
               requestMain += "              <c:IsValidForAdvancedFind i:nil=\"true\" />";
               requestMain += "              <c:SchemaName>new_account_campaign</c:SchemaName>";
               requestMain += "              <c:SecurityTypes i:nil=\"true\" />";
               requestMain += "              <c:AssociatedMenuConfiguration>";
               requestMain += "                <c:Behavior>UseLabel</c:Behavior>";
               requestMain += "                <c:Group>Details</c:Group>";
               requestMain += "                <c:Label>";
               requestMain += "                  <a:LocalizedLabels>";
               requestMain += "                    <a:LocalizedLabel>";
               requestMain += "                      <a:IsManaged i:nil=\"true\" />";
               requestMain += "                      <a:Label>Account</a:Label>";
               requestMain += "                      <a:LanguageCode>1033</a:LanguageCode>";
               requestMain += "                    </a:LocalizedLabel>";
               requestMain += "                  </a:LocalizedLabels>";
               requestMain += "                  <a:UserLocalizedLabel i:nil=\"true\" />";
               requestMain += "                </c:Label>";
               requestMain += "                <c:Order>10000</c:Order>";
               requestMain += "              </c:AssociatedMenuConfiguration>";
               requestMain += "              <c:CascadeConfiguration>";
               requestMain += "                <c:Assign>Cascade</c:Assign>";
               requestMain += "                <c:Delete>Cascade</c:Delete>";
               requestMain += "                <c:Merge>Cascade</c:Merge>";
               requestMain += "                <c:Reparent>Cascade</c:Reparent>";
               requestMain += "                <c:Share>Cascade</c:Share>";
               requestMain += "                <c:Unshare>Cascade</c:Unshare>";
               requestMain += "              </c:CascadeConfiguration>";
               requestMain += "              <c:ReferencedAttribute i:nil=\"true\" />";
               requestMain += "              <c:ReferencedEntity>account</c:ReferencedEntity>";
               requestMain += "              <c:ReferencingAttribute i:nil=\"true\" />";
               requestMain += "              <c:ReferencingEntity>campaign</c:ReferencingEntity>";
               requestMain += "            </b:value>";
               requestMain += "          </a:KeyValuePairOfstringanyType>";
               requestMain += "        </a:Parameters>";
               requestMain += "        <a:RequestId i:nil=\"true\" />";
               requestMain += "        <a:RequestName>CreateOneToMany</a:RequestName>";
               requestMain += "      </request>";
               requestMain += "    </Execute>";
               requestMain += "  </s:Body>";
               requestMain += "</s:Envelope>";
               var req = new XMLHttpRequest();
               req.open("POST", SDK.SAMPLES._getServerUrl(), true)
               // Responses will return XML. It isn't possible to return JSON.
               req.setRequestHeader("Accept", "application/xml, text/xml, */*");
               req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
               req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
               var successCallback = null;
               var errorCallback = null;
               req.onreadystatechange = function () { SDK.SAMPLES.CreateOneToManyResponse(req, successCallback, errorCallback); };
               req.send(requestMain);
           },
       CreateOneToManyResponse: function (req, successCallback, errorCallback) {
               ///<summary>
               /// Recieves the assign response
               ///</summary>
               ///<param name="req" Type="XMLHttpRequest">
               /// The XMLHttpRequest response
               ///</param>
               ///<param name="successCallback" Type="Function">
               /// The function to perform when an successfult response is returned.
               /// For this message no data is returned so a success callback is not really necessary.
               ///</param>
               ///<param name="errorCallback" Type="Function">
               /// The function to perform when an error is returned.
               /// This function accepts a JScript error returned by the _getError function
               ///</param>
               if (req.readyState == 4) {
               if (req.status == 200) {
               if (successCallback != null)
               { successCallback(); }
               }
               else {
                   errorCallback(SDK.SAMPLES._getError(req.responseXML));
               }
           }
       },
       _getError: function (faultXml) {
           ///<summary>
           /// Parses the WCF fault returned in the event of an error.
           ///</summary>
           ///<param name="faultXml" Type="XML">
           /// The responseXML property of the XMLHttpRequest response.
           ///</param>
           var errorMessage = "Unknown Error (Unable to parse the fault)";
           if (typeof faultXml == "object") {
               try {
                   var bodyNode = faultXml.firstChild.firstChild;
                   //Retrieve the fault node
                   for (var i = 0; i < bodyNode.childNodes.length; i++) {
                       var node = bodyNode.childNodes[i];
                       //NOTE: This comparison does not handle the case where the XML namespace changes
                       if ("s:Fault" == node.nodeName) {
                       for (var j = 0; j < node.childNodes.length; j++) {
                           var faultStringNode = node.childNodes[j];
                           if ("faultstring" == faultStringNode.nodeName) {
                               errorMessage = faultStringNode.text;
                               break;
                           }
                       }
                       break;
                   }
               }
           }
           catch (e) { };
        }
        return new Error(errorMessage);
     },
 __namespace: true
};




To understand how to parse the response please review my post on using the DOM parser.
Now you can call the SDK.SAMPLES.CreateOneToManyRequest function from your form jscript handler.
Thats all there is to it!

I hope this helps!