locked
Get values OnLoad from Case RRS feed

  • Question

  • Hi
    How can I get values (update) from Case using OnLoad?

    My situation is:

    1. Customer Joe Johnson writes e-mail to Customer Service.
    2. E-mail arrives in Queue wich recognize Joe Johnsons e-mail address.
    3. Customer Service Member see the e-mail and hit the Accept... button.
    4. Then, In Progress Queue open the e-mail and under Actions... hit Convert to Case...
    5. HELP PART:
      The popup shows Customer*: Joe Johnson
      Open the new Case: check
      Close the e-mail form: check

      I want to run Cases on Regarding Company of Contact, not the Contact it self. Therefore I have tried to do a workflow that update Customer and Responsible Contact. This WF works, it set Responsible Contact to: Joe Johnson and Company to: Johnson Wheels Company.
    6. From this popup I justs want to hit OK. Then my WF do its work.
    7. WF runs on Case create, but since this WF runs just when I hit OK, I don't see the work in my Case form when this pops up. (I can close the form and reopen it, then I will see the updated values that my WF did.
    8. HELP PART: How do I retrieve the values, that the WF just submitted to Case in the database?
      Could be done with some java-script on the OnLoad, right? Some kind of "refresh".

    Best regards,

    Henrik Nielsen

    • Edited by QuercusDK Sunday, July 11, 2010 7:31 AM Better explanation
    Sunday, July 11, 2010 7:26 AM

Answers

  • Hi,

    you need java script to switch the account and contact field in case screen..on load script..

    Hope this helps..

    SetRightCustomer();
    
    function SetRightCustomer()
    {
     // if yes check if it is case
     if(crmForm.all.customerid.DataValue[0] !=null)
     {
     // if customer is selected as contact
     if(crmForm.all.customerid.DataValue[0].typename == "contact")
     {
      //if responsible contactid is not selected then
      if(crmForm.all.responsiblecontactid.DataValue == null)
      {
       ReplaceCustomer(crmForm.all.customerid.DataValue[0].id)  
      }
    
      }
     }
    
    }
    
    
    
    function ReplaceCustomer(contactId) 
    { 
    
     var xml = "" + 
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
     "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 
     GenerateAuthenticationHeader() + 
     " <soap:Body>" + 
     " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "  <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
    "  <q1:EntityName>contact</q1:EntityName>" + 
    "  <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    "   <q1:Attributes>" + 
    "   <q1:Attribute>contactid</q1:Attribute>" + 
    "   <q1:Attribute>parentcustomerid</q1:Attribute>" + 
    "   </q1:Attributes>" + 
    "  </q1:ColumnSet>" + 
    "  <q1:Distinct>false</q1:Distinct>" + 
    "  <q1:Criteria>" + 
    "   <q1:FilterOperator>And</q1:FilterOperator>" + 
    "   <q1:Conditions>" + 
    "   <q1:Condition>" + 
    "    <q1:AttributeName>contactid</q1:AttributeName>" + 
    "    <q1:Operator>Equal</q1:Operator>" + 
    "    <q1:Values>" + 
    "    <q1:Value xsi:type=\"xsd:string\">" + contactId+ "</q1:Value>" + 
    "    </q1:Values>" + 
    "   </q1:Condition>" + 
    "   </q1:Conditions>" + 
    "  </q1:Criteria>" + 
    "  </query>" + 
    " </RetrieveMultiple>" + 
    " </soap:Body>" + 
    "</soap:Envelope>" + 
    "";
    
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    
    var resultXml = xmlHttpRequest.responseXML;
    
    //alert(resultXml);
    
    
    
    if(resultXml !=null)
    { 
     var accountId= retriveText(resultXml.selectNodes("//BusinessEntity/q1:parentcustomerid"));  
     if(accountId!="")
     {
       //Create an array to set as the DataValue for the lookup control.  
       var lookupData = new Array(); 
       
       //Create an Object add to the array.  
       var lookupItem= new Object();
      
       //Set the id, typename, and name properties to the object.  
       lookupItem.id = accountId;  
       lookupItem.typename = 'account'; 
    
       var lookupname = retriveName(lookupItem.id);  
     
       lookupItem.name = lookupname;
    
       // Add the object to the array.  
       lookupData[0] = lookupItem; 
    
      //Set Responsible Contact from existing customer (as customer is contact)
      crmForm.all.responsiblecontactid.DataValue = crmForm.all.customerid.DataValue;
    
       // Set the value of the lookup field to the value of the array.   
       crmForm.all.customerid.DataValue = lookupData; 
     
      } 
    
     }
    
    }
    
    function retriveText(InputNode)
    {
     var text = "";
    
      if (InputNode !=null)
      {
      //alert(InputNode[0].text);
      if(InputNode[0]!=null)
      {
       text =InputNode[0].text; 
      }
      } 
    
     return text;
    }
    
    
    function retriveName(accountNodeId)
    {
     var textReturn = "";
    
      if (accountNodeId!=null)
      {
       var xml = "" + 
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
     "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 
     GenerateAuthenticationHeader() + 
     " <soap:Body>" + 
     " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "  <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
    "  <q1:EntityName>account</q1:EntityName>" + 
    "  <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    "   <q1:Attributes>" + 
    "   <q1:Attribute>accountid</q1:Attribute>" + 
    "   <q1:Attribute>name</q1:Attribute>" + 
    "   </q1:Attributes>" + 
    "  </q1:ColumnSet>" + 
    "  <q1:Distinct>false</q1:Distinct>" + 
    "  <q1:Criteria>" + 
    "   <q1:FilterOperator>And</q1:FilterOperator>" + 
    "   <q1:Conditions>" + 
    "   <q1:Condition>" + 
    "    <q1:AttributeName>accountid</q1:AttributeName>" + 
    "    <q1:Operator>Equal</q1:Operator>" + 
    "    <q1:Values>" + 
    "    <q1:Value xsi:type=\"xsd:string\">" + accountNodeId + "</q1:Value>" + 
    "    </q1:Values>" + 
    "   </q1:Condition>" + 
    "   </q1:Conditions>" + 
    "  </q1:Criteria>" + 
    "  </query>" + 
    " </RetrieveMultiple>" + 
    " </soap:Body>" + 
    "</soap:Envelope>" + 
    "";
    
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    
    var resultXml = xmlHttpRequest.responseXML;
    
    //alert(resultXml);
    
    
    if(resultXml !=null)
    { 
     textReturn= retriveText(resultXml.selectNodes("//BusinessEntity/q1:name")); 
    }
    
    } 
    
     return textReturn;
    }
    
    • Marked as answer by Jim Glass Jr Monday, July 12, 2010 8:14 PM
    Monday, July 12, 2010 2:54 PM

All replies

  • Hi,

    As you know WF works on Asyn mode so that you are getting this delay, so you could try to refresh form using

    window.location.reload(true); or you can save your form that will reload the form automatically crmForm.Save();


    Mahain
    Monday, July 12, 2010 4:39 AM
    Moderator
  • Hi,

    you need java script to switch the account and contact field in case screen..on load script..

    Hope this helps..

    SetRightCustomer();
    
    function SetRightCustomer()
    {
     // if yes check if it is case
     if(crmForm.all.customerid.DataValue[0] !=null)
     {
     // if customer is selected as contact
     if(crmForm.all.customerid.DataValue[0].typename == "contact")
     {
      //if responsible contactid is not selected then
      if(crmForm.all.responsiblecontactid.DataValue == null)
      {
       ReplaceCustomer(crmForm.all.customerid.DataValue[0].id)  
      }
    
      }
     }
    
    }
    
    
    
    function ReplaceCustomer(contactId) 
    { 
    
     var xml = "" + 
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
     "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 
     GenerateAuthenticationHeader() + 
     " <soap:Body>" + 
     " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "  <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
    "  <q1:EntityName>contact</q1:EntityName>" + 
    "  <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    "   <q1:Attributes>" + 
    "   <q1:Attribute>contactid</q1:Attribute>" + 
    "   <q1:Attribute>parentcustomerid</q1:Attribute>" + 
    "   </q1:Attributes>" + 
    "  </q1:ColumnSet>" + 
    "  <q1:Distinct>false</q1:Distinct>" + 
    "  <q1:Criteria>" + 
    "   <q1:FilterOperator>And</q1:FilterOperator>" + 
    "   <q1:Conditions>" + 
    "   <q1:Condition>" + 
    "    <q1:AttributeName>contactid</q1:AttributeName>" + 
    "    <q1:Operator>Equal</q1:Operator>" + 
    "    <q1:Values>" + 
    "    <q1:Value xsi:type=\"xsd:string\">" + contactId+ "</q1:Value>" + 
    "    </q1:Values>" + 
    "   </q1:Condition>" + 
    "   </q1:Conditions>" + 
    "  </q1:Criteria>" + 
    "  </query>" + 
    " </RetrieveMultiple>" + 
    " </soap:Body>" + 
    "</soap:Envelope>" + 
    "";
    
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    
    var resultXml = xmlHttpRequest.responseXML;
    
    //alert(resultXml);
    
    
    
    if(resultXml !=null)
    { 
     var accountId= retriveText(resultXml.selectNodes("//BusinessEntity/q1:parentcustomerid"));  
     if(accountId!="")
     {
       //Create an array to set as the DataValue for the lookup control.  
       var lookupData = new Array(); 
       
       //Create an Object add to the array.  
       var lookupItem= new Object();
      
       //Set the id, typename, and name properties to the object.  
       lookupItem.id = accountId;  
       lookupItem.typename = 'account'; 
    
       var lookupname = retriveName(lookupItem.id);  
     
       lookupItem.name = lookupname;
    
       // Add the object to the array.  
       lookupData[0] = lookupItem; 
    
      //Set Responsible Contact from existing customer (as customer is contact)
      crmForm.all.responsiblecontactid.DataValue = crmForm.all.customerid.DataValue;
    
       // Set the value of the lookup field to the value of the array.   
       crmForm.all.customerid.DataValue = lookupData; 
     
      } 
    
     }
    
    }
    
    function retriveText(InputNode)
    {
     var text = "";
    
      if (InputNode !=null)
      {
      //alert(InputNode[0].text);
      if(InputNode[0]!=null)
      {
       text =InputNode[0].text; 
      }
      } 
    
     return text;
    }
    
    
    function retriveName(accountNodeId)
    {
     var textReturn = "";
    
      if (accountNodeId!=null)
      {
       var xml = "" + 
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
     "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 
     GenerateAuthenticationHeader() + 
     " <soap:Body>" + 
     " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "  <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
    "  <q1:EntityName>account</q1:EntityName>" + 
    "  <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    "   <q1:Attributes>" + 
    "   <q1:Attribute>accountid</q1:Attribute>" + 
    "   <q1:Attribute>name</q1:Attribute>" + 
    "   </q1:Attributes>" + 
    "  </q1:ColumnSet>" + 
    "  <q1:Distinct>false</q1:Distinct>" + 
    "  <q1:Criteria>" + 
    "   <q1:FilterOperator>And</q1:FilterOperator>" + 
    "   <q1:Conditions>" + 
    "   <q1:Condition>" + 
    "    <q1:AttributeName>accountid</q1:AttributeName>" + 
    "    <q1:Operator>Equal</q1:Operator>" + 
    "    <q1:Values>" + 
    "    <q1:Value xsi:type=\"xsd:string\">" + accountNodeId + "</q1:Value>" + 
    "    </q1:Values>" + 
    "   </q1:Condition>" + 
    "   </q1:Conditions>" + 
    "  </q1:Criteria>" + 
    "  </query>" + 
    " </RetrieveMultiple>" + 
    " </soap:Body>" + 
    "</soap:Envelope>" + 
    "";
    
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    
    var resultXml = xmlHttpRequest.responseXML;
    
    //alert(resultXml);
    
    
    if(resultXml !=null)
    { 
     textReturn= retriveText(resultXml.selectNodes("//BusinessEntity/q1:name")); 
    }
    
    } 
    
     return textReturn;
    }
    
    • Marked as answer by Jim Glass Jr Monday, July 12, 2010 8:14 PM
    Monday, July 12, 2010 2:54 PM