locked
Close Quote as Won using XrmSvcToolkit and R RRS feed

  • Question

  • Hello Dynamics JS gurus,

    I'm using XrmSvcToolkit, which works great, and I tried to use the SetState function to change a Quote to Won, but I got this error message.

    SCRIPT5022: This message can not be used to set the state of Quote to Won. In order to set state of Quote to Won, use the CloseQuoteRequest Request message instead.: aa_XrmSvcToolkit, line 647 character 17

    Does anyone know a slick way of calling this function (CloseQuoteRequest) from Javascript? I don't need the Order and I don't care about the Close Quote entity, I just need to set the Quote to Won, and set it to a specific Status Reason.

    I found this (http://mileyja.blogspot.com.au/2011/08/close-quote-using-jscript-or-net-in.html) but it seems like a lot of code, and the Status Reason and QuoteId seem to hardcoded in there somewhere it's a bit intimidating to backwards engineer it.  Something simpler and more generic would be nice.  Perhaps using the XrmSvcToolkit Execute function?

    thanks in advance for the help!

    Monday, August 27, 2012 4:00 AM

Answers

  • You should try to use the toolkit's Execute method. The syntax would be something like this. 
       var requestMain = "";
       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:CloseQuoteRequest\" 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>6a33955a-d3bd-e011-8d99-1cc1de7955db</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\">Customer was mean so we just closed it.</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>5</a:Value>";
       requestMain += "            </c:value>";
       requestMain += "          </a:KeyValuePairOfstringanyType>";
       requestMain += "        </a:Parameters>";
       requestMain += "        <a:RequestId i:nil=\"true\" />";
       requestMain += "        <a:RequestName>CloseQuote</a:RequestName>";
       requestMain += "      </request>";
       requestMain += "    </Execute>";
    
       XrmSvcToolkit.execute({
           executeXml : requestMain 
       });

    I borrowed the code from Jamie's blog post, you would want to parameterize quoteid (6a33955a-d3bd-e011-8d99-1cc1de7955db in the above code) and subject fields. 

    I haven't tested the code, but this should be the way to go. 

    Hope this helps. 


    Daniel Cai | http://danielcai.blogspot.com | @danielcai | Data Integration made easy with SSIS Integration Toolkit

    • Marked as answer by NateOne Monday, August 27, 2012 6:13 AM
    Monday, August 27, 2012 4:53 AM

All replies

  • You should try to use the toolkit's Execute method. The syntax would be something like this. 
       var requestMain = "";
       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:CloseQuoteRequest\" 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>6a33955a-d3bd-e011-8d99-1cc1de7955db</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\">Customer was mean so we just closed it.</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>5</a:Value>";
       requestMain += "            </c:value>";
       requestMain += "          </a:KeyValuePairOfstringanyType>";
       requestMain += "        </a:Parameters>";
       requestMain += "        <a:RequestId i:nil=\"true\" />";
       requestMain += "        <a:RequestName>CloseQuote</a:RequestName>";
       requestMain += "      </request>";
       requestMain += "    </Execute>";
    
       XrmSvcToolkit.execute({
           executeXml : requestMain 
       });

    I borrowed the code from Jamie's blog post, you would want to parameterize quoteid (6a33955a-d3bd-e011-8d99-1cc1de7955db in the above code) and subject fields. 

    I haven't tested the code, but this should be the way to go. 

    Hope this helps. 


    Daniel Cai | http://danielcai.blogspot.com | @danielcai | Data Integration made easy with SSIS Integration Toolkit

    • Marked as answer by NateOne Monday, August 27, 2012 6:13 AM
    Monday, August 27, 2012 4:53 AM
  • Daniel,

    That worked great!  thanks!

    I just replaced that guid with " + quoteId + " and it worked fine.  (I also changed the subject to something a but more in line with our business process :)

    cheers!

    NateOne

    Monday, August 27, 2012 6:20 AM