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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

JavaScript that triggers based on field A on Entity A and sets Field B on Entity B

(0) ShareShare
ReportReport
Posted on by

So

I have a lookup field A for accounts on Entity A.
When somebody changes that field I want the same account to be set on Lookup field B on Entity B.

Trying to google some examples but can't find any for this scenario.

I have the same question (0)
  • Suggested answer
    PabloCRP Profile Picture
    1,088 on at

    Hi, you must make so minor changes

    function serLookUp(context){
    var formContext = context.getFormContext();
    var lookupAName = "new_examplelookup";//Your lookup logicalName in entity A
    var lookupA = formContext.getAttribute(lookupAName).getValue();
    var entityNameB = "new_entity";//Your entity B logical Name  
    var entityNameBId = "9e39ca39-0d05-4700-9c21-23addfbf1f2b";//Your entity B GUID, You can retrive it with API or by passing it as parameter to this function
    var lookupBSchemaName = "new_ExampleEntityB";//Your lookup SCHEMA NAME in entity B
    var datalookupB = generateData(lookupA,entityNameBFieldSchemaName);
    Xrm.WebApi.updateRecord(entityNameB,entityNameBId,datalookupB).then(
    	function(res){
    		alert("Update success");
    	},
    	function(err){
    		console.log(err);
    	},
    );
    }
    
    function generateData(lookup,lookupBSchemaName){
    	var data = {};
    	var lookupBSchemaNameTemp = lookupBSchemaName "@odata.bind";
    	if(lookup!==null)
    		data[lookupBSchemaNameTemp] = "/accounts(" lookup[0].id.replace(/[{|}]/g,"") ")";
    	else
    		data[lookupBSchemaNameTemp] = null;
    
    	return data;
    }

    regards.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
iampranjal Profile Picture

iampranjal 51

#2
Martin Dráb Profile Picture

Martin Dráb 39 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 26 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans