locked
Customize CRM RRS feed

  • Question

  • Dears,<o:p></o:p>

    i have big
    problem i am try to customize some field on case form using JavaScript i have tried
    a lot of time but no any result ,<o:p></o:p>

    i have one
    lookup field name ("customerid") i want when open case direct from
    CRM without return back to account it fill account name on this automatic on
    this lookup field ("customerid") depend on the user login ?<o:p></o:p>

    for example
    i have login into crm and i go to file from menu and press on new record and
    click on new case, when open this case i cannot see my account name in lookup
    field i want when open this case see account name when form is load please help
    me ?????<o:p></o:p>



    Wednesday, September 5, 2012 1:52 PM

Answers

  • Hi Khaleel,

    Correct me if I am wrong; you have an account setup for every CRM User and you want to populate customer field with that user account. 

    Here is how you can populate customer lookup on form load with an account that has the same owner as case owner. I have CRM version 4.0 and below code is working fine on it. Use it on onload event of case form. You can use the following tool to convert it to CRM 2011. http://crm2011scriptconvert.codeplex.com/releases/view/52074

    I have tried this tool but when I try to run this tool it gives me old blue dumping screen..... I hope you won't face that. Best of Luck!!!!

    var user = new Array();
    user = crmForm.all.ownerid.DataValue;
    var userid = user[0].id;
    
    
       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>"+"name" +"</q1:Attribute>" + 
    "      <q1:Attribute>"+"accountid" +"</q1:Attribute>" + 
    "     </q1:Attributes>" + 
    "    </q1:ColumnSet>" + 
    "    <q1:Distinct>false</q1:Distinct>" + 
    "    <q1:Criteria>" + 
    "     <q1:FilterOperator>And</q1:FilterOperator>" + 
    "     <q1:Conditions>" + 
    "      <q1:Condition>" + 
    "       <q1:AttributeName>"+ "ownerid" +"</q1:AttributeName>" + 
    "       <q1:Operator>Equal</q1:Operator>" + 
    "       <q1:Values>" + 
    "        <q1:Value xsi:type=\"xsd:string\">" + userid + "</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;
     if(resultXml !=null)
        {  
         var account = new Array();
          account[0] = new Object();
          var accountName = resultXml.selectNodes("//BusinessEntity/q1:"+('name'));     
          account[0].name =  accountName[0].text;
           account[0].typename = 'account';
          crmForm.all.customerid.DataValue = account;
         }    
      


    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful" Thanks, Imran Abbasi


    Monday, September 10, 2012 5:47 AM

All replies

  • hi,

    this can be done only for one account 

    for example

    In your CRM there are lot of accounts in it there is a account with name "Khaleel"

    if you need to display "Khaleel" in customer Look up of Case entity you can do by the following way

    function onLoad_Case() {
    
        var value = new Array();
    
        value[0] = new Object();
    
        value[0].id = "32 digit Guid Id"; //Khaleel Account Guid ID
    
        value[0].name = "Khaleel";
    
        value[0].entityType = 1;
    
    
        //set to customer lookup on Case
        Xrm.Page.getAttribute("customerid").setValue(value);
    
    }


    Please don't forget to Vote and marked as answer If this post answers your question or was helpful, please click "Mark As Answer" on the post and "Mark as Helpful" Be wise

    Wednesday, September 5, 2012 3:15 PM
  • Hi Anwar

    Greeting ,,,

    thank you for quick response, this code it will fill the customer field Manually and when you need to save the case it show you error message record is unavailable because is Deal with it as new account not with the current Account  and i need to get the old account from data base depend on the current user login and fill it automatic in the field

    Not :

    if i can get the GUID automatic for the current account from page on load i can fill it automatic without any problem so how i can get the GUID for the current account on page onload ?

    Thursday, September 6, 2012 7:03 PM
  • any update ?
    Sunday, September 9, 2012 9:56 AM
  • Hi Khaleel,

    Correct me if I am wrong; you have an account setup for every CRM User and you want to populate customer field with that user account. 

    Here is how you can populate customer lookup on form load with an account that has the same owner as case owner. I have CRM version 4.0 and below code is working fine on it. Use it on onload event of case form. You can use the following tool to convert it to CRM 2011. http://crm2011scriptconvert.codeplex.com/releases/view/52074

    I have tried this tool but when I try to run this tool it gives me old blue dumping screen..... I hope you won't face that. Best of Luck!!!!

    var user = new Array();
    user = crmForm.all.ownerid.DataValue;
    var userid = user[0].id;
    
    
       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>"+"name" +"</q1:Attribute>" + 
    "      <q1:Attribute>"+"accountid" +"</q1:Attribute>" + 
    "     </q1:Attributes>" + 
    "    </q1:ColumnSet>" + 
    "    <q1:Distinct>false</q1:Distinct>" + 
    "    <q1:Criteria>" + 
    "     <q1:FilterOperator>And</q1:FilterOperator>" + 
    "     <q1:Conditions>" + 
    "      <q1:Condition>" + 
    "       <q1:AttributeName>"+ "ownerid" +"</q1:AttributeName>" + 
    "       <q1:Operator>Equal</q1:Operator>" + 
    "       <q1:Values>" + 
    "        <q1:Value xsi:type=\"xsd:string\">" + userid + "</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;
     if(resultXml !=null)
        {  
         var account = new Array();
          account[0] = new Object();
          var accountName = resultXml.selectNodes("//BusinessEntity/q1:"+('name'));     
          account[0].name =  accountName[0].text;
           account[0].typename = 'account';
          crmForm.all.customerid.DataValue = account;
         }    
      


    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful" Thanks, Imran Abbasi


    Monday, September 10, 2012 5:47 AM
  • Hi Imran

    Greeting ,,,

    first i want to thank you for your great efforts with us to find the solution for my issue it help me alot i just added the following comand with your code :

    var aacountId = resultXml.selectNodes("//BusinessEntity/q1:"+('accountid'));

    account[0].id=  accountId[0].text;

    then it gathered the account id to populate case to that particular account so thank you and i wish for you to hapy in CRM...... ;-)

    Tuesday, September 11, 2012 8:54 AM
  • Hi Khaleel,

    I am glad that I was able to help. 

    Regards,


    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful" Thanks, Imran Abbasi

    Tuesday, September 11, 2012 9:08 AM