web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Auto populate City and State

(0) ShareShare
ReportReport
Posted on by

Hi,

I have a look up on Account Entity , Custom entity A.
In that custom entity I have 2 Single line of text City and State.
One I select a Custom entity in lookup I need to auto populate the City and State in Account entity City , State.

Let me know how to write the J script for this. If some one helps me on this highly appreciated.

Thanks,

Rahul..

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at
    RE: Auto populate City and State

    Hi Rahul,

    You could do this with javascript, but I don't think it's necessary to use custom dev. Have you looked at using a Business Rule? Check out: www.microsoft.com/.../create-business-rules-and-recommendations-to-apply-logic-in-a-form.aspx

    You'd set up a business rule to run when the lookup changes, then update the account fields based on the related record (it's not documented but you can select related fields using dot notation, something like "primarycontactid.firstname" ).

    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

     Aiden

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Auto populate City and State

    Have you tried writing a workflow for the Account entity that runs on update of the custom entity lookup field? If the field contains data, set the Account City and State fields to the City and State values defined for the related custom entity record. If the field does not contain data, clear Account City and State.

  • Suggested answer
    Drew Poggemann Profile Picture
    4 on at
    RE: Auto populate City and State

    Hi Rahul,

    The easiest way I have done this is through the "Mappings".  When you create a relationship between one entity and another in a parent to child type of relationship or a 1-N relationships (in general) you can define mappings from one entity to the other on creation.  Example, this is done out of the box for Lead when it creates the Account, Contact and the Opportunity entities.

    https://technet.microsoft.com/en-us/library/dn531171.aspx?f=255&MSPPError=-2147217396#BKMK_mappingEntityFields

    The following is an old article but mostly valid to navigate and setup even in new CRM environments.

    http://crm.fullscope.com/save-time-entering-data-into-crm-by-mapping-fields-between-records/

    Hope this helps without needing to do JavaScript or Business Rules...

    Thanks much!

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: Auto populate City and State

    Hi Rahul,

    You could write javascript for this to retrieve data of one entity to another entity using java-script. Please refer the community thread below for the code.

    community.dynamics.com/.../139190

  • Suggested answer
    Alagunellaikumar Profile Picture
    6,212 on at
    RE: Auto populate City and State

    Hi

    You have download the SDK.REST from msdn, add that file in the account form. IN the custom lookup on change event put the below code

    SDK.REST.retrieveRecord(CustomLookupId, "Custom Logical Name", null, null, getDetails, errorHandler);

    CustomLookupId= id get from custom lookup

    Custom Logical Name= entity name of custom lookup

    function getDetails(customResult) {

    Xrm.Page.getAttribute('city').setValue(customResult.city);

    }

    PLease refer the below url

    arunpotti.wordpress.com/.../restretrieveexample

  • AbiRami Profile Picture
    516 on at
    RE: Auto populate City and State

    Hi Aiden Kaskela,

    How could you acheive the above scenerio in business rule? Because when i try to set a custom field in contact entity with mainphone value of account entity, i couldnt able to get the value of mainphone instead i am just getting the value which i entered in Business rule action(parentaccountid.telephone1). Am i going in the right way? please suggest.

    5383.2.png

     

    5383.2.png

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Auto populate City and State

    Instead of Type as Value use field

  • Suggested answer
    Rushikesh Bhujbal Profile Picture
    285 on at
    RE: Auto populate City and State

    Add City and State to your Lookup View and call "getCityState()" function on onchange of lookup.

    function getCityState() {

       Xrm.Page.getAttribute(lookupField).getValue();

       var lookupSelectedRecord = [];

       var city;

       var state;

       lookupSelectedRecord = Xrm.Page.getAttribute(lookupField).getValue()[0].keyValues;

       if (lookupSelectedRecord.new_fullname != null) {

           city = lookupSelectedRecord.city;

           state = lookupSelectedRecord.state;

       }

       else {

           lookupSelectedRecord = JSON.parse(Xrm.Page.getAttribute(lookupField).getValue()[0].keyValues);

           city = lookupSelectedRecord.city;

           state = lookupSelectedRecord.state;

       }

    }

    You can do it using web api also.

  • AbiRami Profile Picture
    516 on at
    RE: Auto populate City and State

    Hi Saad Akhtar,

    Its not possible using field.

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: Auto populate City and State

    @Abi Rami,

    You could use the code in the following thread to accomplish your task.

    community.dynamics.com/.../139190

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans