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
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
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.
Can anyone please share me the java script for Auto populate fields in account entity when new contact record is created.
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.
Note : If you want the copying to happen instantly, you can convert the workflow to be a real-time one.
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.
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
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
André Arnaud de Cal...
292,516
Super User 2025 Season 1
Martin Dráb
231,387
Most Valuable Professional
nmaenpaa
101,156