locked
Porting CRM 4 code to CRM 2011 standards question RRS feed

  • Question

  • Hello guys I have been porting over crm 4 javascript webresources to use the CRM 2011 framework and almost everything has been easy and straight forward. Everything except for the following lines.

    I think the following line is trying to set the state of the quote to accept? If not then do some other logic? What logically is this code trying to do? Would the port be trying to set the state of the Quote entity to accept using a SOAP or REST call?

    if (!crmForm.SubmitCrmForm(QUOTE_QUOTE_ACCEPT_EVENT, true, true, false)) {

    // Then do something here

    What about here? Is it trying to Create an order off of the Quote? So what would the code port be? Creating an order using REST or SOAP?

    crmForm.SubmitCrmForm(QUOTE_CREATE_ORDER_EVENT, true, true, false);


    Thanks in Advance




    Wednesday, July 31, 2013 10:01 PM

Answers

  • Thanks Kalim. I managed to replicate the crmForm.SubmitCrmForm(QUOTE_QUOTE_ACCEPT_EVENT, true, true, false) functionality by writing some javascript that encapsulated a SOAP message that turned a Quote into a won status. Then as a successcallback function I wrote another javascript function that encapsulated another method that turned a Quote into a salesorder. My company wanted to bypass the popup that comes up when you want to do this out of the box. I used the soaplogger utility that comes in the CRM SDK "sdk\samplecode\cs\client\soaplogger". This generates a soap message that you copy and paste in a javascript function. Info on the soaplogger tool can be found here:

    http://msdynamics2011.blogspot.com/2011/08/soaplogger.html

    There is another tool that you can use to copy and paste the SOAP message into a window and then you give the function a name and a namespace and it will generate the javascript for you. This tool is described here:

    http://mileyja.blogspot.com/2011/03/crm-2011-jscript-soap-request-formatter.html

    Using these 2 tools I came up with this code below (All you would have to do is call SOAP.QUOTE.WinQuoteRequest(id) from you javascript web resource):

    if (typeof (SOAP) == "undefined")
    { SOAP = { __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.
    SOAP.QUOTE = {
        _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;
        },
        WinQuoteRequest: function (id) {
            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:WinQuoteRequest\" 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>QuoteClose</c:key>";
            requestMain += "            <c:value i:type=\"a:Entity\">";
            requestMain += "              <a:Attributes>";
            requestMain += "                <a:KeyValuePairOfstringanyType>";
            requestMain += "                  <c:key>quoteid</c:key>";
            requestMain += "                  <c:value i:type=\"a:EntityReference\">";
            requestMain += "                    <a:Id>" + id + "</a:Id>";
            requestMain += "                    <a:LogicalName>quote</a:LogicalName>";
            requestMain += "                    <a:Name i:nil=\"true\" />";
            requestMain += "                  </c:value>";
            requestMain += "                </a:KeyValuePairOfstringanyType>";
            requestMain += "                <a:KeyValuePairOfstringanyType>";
            requestMain += "                  <c:key>subject</c:key>";
            requestMain += "                  <c:value i:type=\"d:string\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">Won the Quote</c:value>";
            requestMain += "                </a:KeyValuePairOfstringanyType>";
            requestMain += "              </a:Attributes>";
            requestMain += "              <a:EntityState i:nil=\"true\" />";
            requestMain += "              <a:FormattedValues />";
            requestMain += "              <a:Id>00000000-0000-0000-0000-000000000000</a:Id>";
            requestMain += "              <a:LogicalName>quoteclose</a:LogicalName>";
            requestMain += "              <a:RelatedEntities />";
            requestMain += "            </c:value>";
            requestMain += "          </a:KeyValuePairOfstringanyType>";
            requestMain += "          <a:KeyValuePairOfstringanyType>";
            requestMain += "            <c:key>Status</c:key>";
            requestMain += "            <c:value i:type=\"a:OptionSetValue\">";
            requestMain += "              <a:Value>4</a:Value>";
            requestMain += "            </c:value>";
            requestMain += "          </a:KeyValuePairOfstringanyType>";
            requestMain += "        </a:Parameters>";
            requestMain += "        <a:RequestId i:nil=\"true\" />";
            requestMain += "        <a:RequestName>WinQuote</a:RequestName>";
            requestMain += "      </request>";
            requestMain += "    </Execute>";
            requestMain += "  </s:Body>";
            requestMain += "</s:Envelope>";
            var req = new XMLHttpRequest();
            req.open("POST", SOAP.QUOTE._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 = function () {
                SOAP.QUOTE.ConvertQuoteToSalesOrderRequest(id);
            };
            var errorCallback = null;
            req.onreadystatechange = function () { SOAP.QUOTE.WinQuoteResponse(req, successCallback, errorCallback); };
            req.send(requestMain);
        },
        WinQuoteResponse: 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(SOAP.QUOTE._getError(req.responseXML));
                }
            }
        },
        ConvertQuoteToSalesOrderRequest: function (id) {
            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:ConvertQuoteToSalesOrderRequest\" 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>QuoteId</c:key>";
            requestMain += "            <c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + id + "</c:value>";
            requestMain += "          </a:KeyValuePairOfstringanyType>";
            requestMain += "          <a:KeyValuePairOfstringanyType>";
            requestMain += "            <c:key>ColumnSet</c:key>";
            requestMain += "            <c:value i:type=\"a:ColumnSet\">";
            requestMain += "              <a:AllColumns>false</a:AllColumns>";
            requestMain += "              <a:Columns xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">";
            requestMain += "                <d:string>salesorderid</d:string>";
            requestMain += "                <d:string>totalamount</d:string>";
            requestMain += "              </a:Columns>";
            requestMain += "            </c:value>";
            requestMain += "          </a:KeyValuePairOfstringanyType>";
            requestMain += "        </a:Parameters>";
            requestMain += "        <a:RequestId i:nil=\"true\" />";
            requestMain += "        <a:RequestName>ConvertQuoteToSalesOrder</a:RequestName>";
            requestMain += "      </request>";
            requestMain += "    </Execute>";
            requestMain += "  </s:Body>";
            requestMain += "</s:Envelope>";
            var req = new XMLHttpRequest();
            req.open("POST", SOAP.QUOTE._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 = function () {
                SOAP.QUOTE.TransferToJobPage(id);
            };
            var errorCallback = null;
            req.onreadystatechange = function () { SOAP.QUOTE.ConvertQuoteToSalesOrderResponse(req, successCallback, errorCallback); };
            req.send(requestMain);
        },
        
        ConvertQuoteToSalesOrderResponse: 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(SOAP.QUOTE._getError(req.responseXML));
                }
            }
        },
    
        TransferToJobPage: function (quoteId) {
            var queryOptions = {
                entityName: "salesorder",
                attributes: ["quoteid"],
                values: [quoteId],
                columnSet: ["salesorderid"],
                orderby: ["quoteid"] // Order by firstname and then lastname even though we are only getting one record back
            };
    
            var fetchedSalesOrders = XrmServiceToolkit.Soap.QueryByAttribute(queryOptions);
            salesOrderId = fetchedSalesOrders[0].id;
            //var etc = XrmServiceToolkit.Common.GetObjectTypeCode("salesorder");
            //var url = Xrm.Page.context.getServerUrl() + "/main.aspx?etc=" + etc + "&extraqs=%3fetc%3d" + etc + "%26id%3d%257b" + Job.Globals.Id + "%257d%26pagemode%3diframe&pagetype=entityrecord";
            //window.location.href = url;
            Xrm.Utility.openEntityForm("salesorder", salesOrderId);
        },
    
        _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
    };
    



    Thanks in Advance

    • Marked as answer by Bill Blancett Wednesday, August 7, 2013 5:53 PM
    Wednesday, August 7, 2013 5:52 PM

All replies

  • Hi Bill,

    it is un-supported customization. I think it will be difficult to tell u the exact parameter purpose for the function as it is Internal to MS CRM without any documentation. I think QUOTE_QUOTE_ACCEPT_EVENT is variable that has been assigned some value.

    This internal method managed saving records in CRM 4.0. The supported method to use is Xrm.Page.data.entity.save. If you want to manage how individual attributes are saved you can use the setSubmitMode method of the attribute object.

    The signature for this function is as follows if you wonder what all the bools are about.

    function SubmitCrmForm(iMode,bCheckValid,bForceSubmit,bClose,bBuildFullXml)

    Please refer this blog.

    http://nishantrana.wordpress.com/2009/07/08/recalculate-and-submitcrmform-javascript-function-in-crm/

    Sunday, August 4, 2013 8:33 AM
  • Thanks Kalim. I managed to replicate the crmForm.SubmitCrmForm(QUOTE_QUOTE_ACCEPT_EVENT, true, true, false) functionality by writing some javascript that encapsulated a SOAP message that turned a Quote into a won status. Then as a successcallback function I wrote another javascript function that encapsulated another method that turned a Quote into a salesorder. My company wanted to bypass the popup that comes up when you want to do this out of the box. I used the soaplogger utility that comes in the CRM SDK "sdk\samplecode\cs\client\soaplogger". This generates a soap message that you copy and paste in a javascript function. Info on the soaplogger tool can be found here:

    http://msdynamics2011.blogspot.com/2011/08/soaplogger.html

    There is another tool that you can use to copy and paste the SOAP message into a window and then you give the function a name and a namespace and it will generate the javascript for you. This tool is described here:

    http://mileyja.blogspot.com/2011/03/crm-2011-jscript-soap-request-formatter.html

    Using these 2 tools I came up with this code below (All you would have to do is call SOAP.QUOTE.WinQuoteRequest(id) from you javascript web resource):

    if (typeof (SOAP) == "undefined")
    { SOAP = { __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.
    SOAP.QUOTE = {
        _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;
        },
        WinQuoteRequest: function (id) {
            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:WinQuoteRequest\" 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>QuoteClose</c:key>";
            requestMain += "            <c:value i:type=\"a:Entity\">";
            requestMain += "              <a:Attributes>";
            requestMain += "                <a:KeyValuePairOfstringanyType>";
            requestMain += "                  <c:key>quoteid</c:key>";
            requestMain += "                  <c:value i:type=\"a:EntityReference\">";
            requestMain += "                    <a:Id>" + id + "</a:Id>";
            requestMain += "                    <a:LogicalName>quote</a:LogicalName>";
            requestMain += "                    <a:Name i:nil=\"true\" />";
            requestMain += "                  </c:value>";
            requestMain += "                </a:KeyValuePairOfstringanyType>";
            requestMain += "                <a:KeyValuePairOfstringanyType>";
            requestMain += "                  <c:key>subject</c:key>";
            requestMain += "                  <c:value i:type=\"d:string\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">Won the Quote</c:value>";
            requestMain += "                </a:KeyValuePairOfstringanyType>";
            requestMain += "              </a:Attributes>";
            requestMain += "              <a:EntityState i:nil=\"true\" />";
            requestMain += "              <a:FormattedValues />";
            requestMain += "              <a:Id>00000000-0000-0000-0000-000000000000</a:Id>";
            requestMain += "              <a:LogicalName>quoteclose</a:LogicalName>";
            requestMain += "              <a:RelatedEntities />";
            requestMain += "            </c:value>";
            requestMain += "          </a:KeyValuePairOfstringanyType>";
            requestMain += "          <a:KeyValuePairOfstringanyType>";
            requestMain += "            <c:key>Status</c:key>";
            requestMain += "            <c:value i:type=\"a:OptionSetValue\">";
            requestMain += "              <a:Value>4</a:Value>";
            requestMain += "            </c:value>";
            requestMain += "          </a:KeyValuePairOfstringanyType>";
            requestMain += "        </a:Parameters>";
            requestMain += "        <a:RequestId i:nil=\"true\" />";
            requestMain += "        <a:RequestName>WinQuote</a:RequestName>";
            requestMain += "      </request>";
            requestMain += "    </Execute>";
            requestMain += "  </s:Body>";
            requestMain += "</s:Envelope>";
            var req = new XMLHttpRequest();
            req.open("POST", SOAP.QUOTE._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 = function () {
                SOAP.QUOTE.ConvertQuoteToSalesOrderRequest(id);
            };
            var errorCallback = null;
            req.onreadystatechange = function () { SOAP.QUOTE.WinQuoteResponse(req, successCallback, errorCallback); };
            req.send(requestMain);
        },
        WinQuoteResponse: 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(SOAP.QUOTE._getError(req.responseXML));
                }
            }
        },
        ConvertQuoteToSalesOrderRequest: function (id) {
            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:ConvertQuoteToSalesOrderRequest\" 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>QuoteId</c:key>";
            requestMain += "            <c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + id + "</c:value>";
            requestMain += "          </a:KeyValuePairOfstringanyType>";
            requestMain += "          <a:KeyValuePairOfstringanyType>";
            requestMain += "            <c:key>ColumnSet</c:key>";
            requestMain += "            <c:value i:type=\"a:ColumnSet\">";
            requestMain += "              <a:AllColumns>false</a:AllColumns>";
            requestMain += "              <a:Columns xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">";
            requestMain += "                <d:string>salesorderid</d:string>";
            requestMain += "                <d:string>totalamount</d:string>";
            requestMain += "              </a:Columns>";
            requestMain += "            </c:value>";
            requestMain += "          </a:KeyValuePairOfstringanyType>";
            requestMain += "        </a:Parameters>";
            requestMain += "        <a:RequestId i:nil=\"true\" />";
            requestMain += "        <a:RequestName>ConvertQuoteToSalesOrder</a:RequestName>";
            requestMain += "      </request>";
            requestMain += "    </Execute>";
            requestMain += "  </s:Body>";
            requestMain += "</s:Envelope>";
            var req = new XMLHttpRequest();
            req.open("POST", SOAP.QUOTE._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 = function () {
                SOAP.QUOTE.TransferToJobPage(id);
            };
            var errorCallback = null;
            req.onreadystatechange = function () { SOAP.QUOTE.ConvertQuoteToSalesOrderResponse(req, successCallback, errorCallback); };
            req.send(requestMain);
        },
        
        ConvertQuoteToSalesOrderResponse: 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(SOAP.QUOTE._getError(req.responseXML));
                }
            }
        },
    
        TransferToJobPage: function (quoteId) {
            var queryOptions = {
                entityName: "salesorder",
                attributes: ["quoteid"],
                values: [quoteId],
                columnSet: ["salesorderid"],
                orderby: ["quoteid"] // Order by firstname and then lastname even though we are only getting one record back
            };
    
            var fetchedSalesOrders = XrmServiceToolkit.Soap.QueryByAttribute(queryOptions);
            salesOrderId = fetchedSalesOrders[0].id;
            //var etc = XrmServiceToolkit.Common.GetObjectTypeCode("salesorder");
            //var url = Xrm.Page.context.getServerUrl() + "/main.aspx?etc=" + etc + "&extraqs=%3fetc%3d" + etc + "%26id%3d%257b" + Job.Globals.Id + "%257d%26pagemode%3diframe&pagetype=entityrecord";
            //window.location.href = url;
            Xrm.Utility.openEntityForm("salesorder", salesOrderId);
        },
    
        _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
    };
    



    Thanks in Advance

    • Marked as answer by Bill Blancett Wednesday, August 7, 2013 5:53 PM
    Wednesday, August 7, 2013 5:52 PM