locked
CRm 2013 online - jscript to populate a custom text field based on on look up record. RRS feed

  • Question

  • In CRM 2013 online - I have a custom field in Contact form "Customer account Number"  

    whenever user change the Customer Lookup field, we would like to automatically populate the "Customer Account Number" with the value from Account record.  Every Account has a account number column and we have entered a unique number. 

    Generally when a contact is created under a particular account, the custom account number is automatically entered (we mapped the fields).  However, when a user changes the customer from the account look up field in Contact Form (i.e. a contact was wrongly associated), then we want a jscript to automatically populate the customer account number column in the Contact Form so that user verifies it's the correct customer that the contact is going tobe associated to before he saves the contact form. 

    This is for CRM 2013 online and not for CRM 2011 (we had a script that was working on CRM 2011 but doesn't work for CRM 2013). 

    Tuesday, January 7, 2014 4:55 PM

Answers

  • You can try to adapt the script of this post:

    http://www.crmanswers.net/2013/04/get-current-users-full-name-with.html

    You need to change the entity name and the guid inside the open request and put the correct field name (schema name) after the JSON parse.


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by Ronald Liu Tuesday, January 7, 2014 8:16 PM
    • Marked as answer by CRM elite Wednesday, January 8, 2014 1:24 AM
    Tuesday, January 7, 2014 6:16 PM
  • Ok.

    Seems to be not obvious as it is for me.

    So step by step instructions are:

    1. Install Odata Query builder.

    2. Using tool from step 1 build query to point to correct schema names of entity and account number attribute.

    3. Use code from Retrieve section from mentioned article.

    4. Get account Id using Xrm.Page.getAttribute("parentcustomerid").getValue()[0].id code snippet.

    5. Combine everything from steps 1-4 to get code that will retrieve account number based on account id.

    6. Create a JS function that will use code from point 5 and register this function as a OnChange handler for parentcustomerid field change.


    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog

    • Marked as answer by CRM elite Wednesday, January 8, 2014 1:25 AM
    Tuesday, January 7, 2014 9:04 PM
    Moderator

All replies

  • Hello,

    You can use OData to get account number. You can see sample here - http://msdn.microsoft.com/en-us/library/gg334427.aspx


    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog

    Tuesday, January 7, 2014 5:03 PM
    Moderator
  • Hi - thanks. this page talks about the below.. is that correct?  Its very difficult to understand just to get one piece of script --- is there a simplified version or could you be able to provide the script here taking my req as a sample.  much appreciate it.  

    All we need is - on change of one look up field,  script should fill the data in another text field.. 

     

    Sample: Create, Retrieve, Update and Delete Using the REST Endpoint with JavaScript

    Tuesday, January 7, 2014 5:46 PM
  • You can try to adapt the script of this post:

    http://www.crmanswers.net/2013/04/get-current-users-full-name-with.html

    You need to change the entity name and the guid inside the open request and put the correct field name (schema name) after the JSON parse.


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by Ronald Liu Tuesday, January 7, 2014 8:16 PM
    • Marked as answer by CRM elite Wednesday, January 8, 2014 1:24 AM
    Tuesday, January 7, 2014 6:16 PM
  • Ok.

    Seems to be not obvious as it is for me.

    So step by step instructions are:

    1. Install Odata Query builder.

    2. Using tool from step 1 build query to point to correct schema names of entity and account number attribute.

    3. Use code from Retrieve section from mentioned article.

    4. Get account Id using Xrm.Page.getAttribute("parentcustomerid").getValue()[0].id code snippet.

    5. Combine everything from steps 1-4 to get code that will retrieve account number based on account id.

    6. Create a JS function that will use code from point 5 and register this function as a OnChange handler for parentcustomerid field change.


    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog

    • Marked as answer by CRM elite Wednesday, January 8, 2014 1:25 AM
    Tuesday, January 7, 2014 9:04 PM
    Moderator