Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Auto populate City and State

Posted on by Microsoft Employee

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

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

    Hi Aiden Kaskela,

    No issues. Thanks for your time. Thank you Nithya Gopinath.

  • Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: Auto populate City and State

    Hi Abi,

    I have to offer my apologies, I was mistaken. You're able to use that notation using calculated fields (and the post I was reading referenced business rules, but it isn't available there: http://www.inogic.com/blog/2015/07/accessing-related-entities-fields-in-calculated-fields-formulas-in-microsoft-dynamics-crm-2015-online-update-1/ )

    Again, my apologies for the confusion.

    Thanks,

      Aiden

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

    @Abi Rami,

    I think it is not possible to do this stuff using business rules.

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

    Hi Nithya,

    Yes i can. I just want to know is it possible to achieve this task using business rule as Aiden Kaskela said.

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 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

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

    Hi Saad Akhtar,

    Its not possible using field.

  • Suggested answer
    Rushikesh Bhujbal Profile Picture
    Rushikesh Bhujbal 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.

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

    Instead of Type as Value use field

  • AbiRami Profile Picture
    AbiRami 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
    Alagunellaikumar Profile Picture
    Alagunellaikumar 6,210 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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans