Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Ms dynamics crm javascript

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Auto populate common fields using javascript

In Contact form,if i give value and save it should auto populate in account form common fields 

And it should get added in lookup record.

*This post is locked for comments

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,052 on at
    RE: Ms dynamics crm javascript

    Hi

    Have a look at the JS examples in the posts below

    community.dynamics.com/.../124723

    community.dynamics.com/.../549377

    If the above links does not help, please let us know and also provide more details on what fields and how and when you want to populate them.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Ms dynamics crm javascript

    Can anyone please share me the java script for Auto populate fields in account entity when new contact record is created.

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,052 on at
    RE: Ms dynamics crm javascript

    Krithika

    Since you only want to copy values from Contact to Account only after Contact saved, you can achieve this by creating a Workflow that triggers on Contact Create / update of a particular field if that's what you are after.

    In this workflow, you can copy values from Contact to parent account.

    3276.ScreenClip-_5B00_64_5D00_.png

    Note : If you want the copying to happen instantly, you can convert the workflow to be a real-time one.

  • Suggested answer
    Kalpavruksh D365 CoE Profile Picture
    Kalpavruksh D365 CoE 2,545 on at
    RE: Ms dynamics crm javascript

    There is another way to auto-populate i.e. using plugin if its ok to have the functionality in the background which will be helpful while creating contact records automatically.

    Please mark this answer as verified, if it has helped you.

  • Suggested answer
    DKasp Profile Picture
    DKasp 229 on at
    RE: Ms dynamics crm javascript

    Javascript is for stuff that you want to do "while the user is watching" - for example: When you are creating a new Contact and select an Account for this Contact, and you want e.g. the address to be pulled from the account IMMEDIATELY.

    Mappings (well, and plugins) can do the same, but only when you actually submit the new Contact (=when you save) as they respond to that.

    If you want to populate fields with Javascript, it works like this:

        var value = "hello world";
    Xrm.Page.getAttribute("fieldname").setValue(value);

    And if you really want to set values from e.g. the account while the user is entering the new Contact, you'll have to do this via the API - for example:

    var accountId = Xrm.Page.getAttribute("accountid").getValue(); // get the Account id you picked on the Contact form
    var fieldList = "name,city,whatever"; // list of attributes to retrieve from Account
    
    var request = new XMLHttpRequest();
    var query = "?$select="+fieldList;
    var reqLine = Xrm.Page.context.getClientUrl(); // makes sure the call goes to the correct server url
    reqLine+="/api/data/v9.1"; // calling the 9.1 api
    reqLine+="/accounts"; // query the Account table - note you HAVE to use plural here.
    reqLine+="("+accountId[0].id.slice(1, -1)+")"; // looking for the accountId from above.
    reqLine+=query; // add the select statement from above to indicate which fields you want to retrieve
    // configure the request
    request.open("GET",reqLine, true);
    request.setRequestHeader("OData-MaxVersion","4.0");
    request.setRequestHeader("OData-Version","4.0");
    request.setRequestHeader("Accept","application/json");
    request.setRequestHeader("Content-Type","application/json; charset=utf-8");
    request.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    // set up a function to handle the results and process them
    request.onreadystatechange = function () {
        if (this.readyState === 4) {
            request.onreadystatechange = null;
            if (this.status === 200) {
                var result = JSON.parse(this.response); // parses the JSON response to an object
                var name = result["name"]; // grab the attribute 'name' from the result
                Xrm.Page.getAttribute("name").setValue(name); // and write it to the field 'name' on the form
            } else {
                alert("attempted to retrieve account="+accountId+"\nstatus is "+this.status+"\nresponse is:\n"+this.response);
            }
        }
    }
    request.send(); // do not, EVER, forget this line!

    For reference: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/web-api-query-data-sample-client-side-javascript

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Ms dynamics crm javascript

    Hi Krithika,

    Can you please elobarate your query little more.

    As per my understanding.. You are having 1 to N relationship from account to contact, So some fields to be auto mapped from account to contact. If this is  your query you need to crate mapping from account to contact.

    You can find mappings in 1:N relationship. While creating contact from account subgrid those fields automatically populated and also account lookup will be automatically updated in Contact form.

    Regards,

    Sravan. J

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,387 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans