Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Resco CRM - assign value to field from field from another entity

Posted on by Microsoft Employee

Hi All,

I have the following task - in Order I must fill the custom field from corresponding custom field from Account.

I use the following function (in js-file):

function onCustomerChanged(entityForm) {
if (entityForm.context.changedItem == "customerid") {
		accountId = entityForm.entity.properties.customerid.id;  
		if(entityForm.entity.properties.avanade_wholesaleraccountno == null)
		{
			var account = new MobileCRM.FetchXml.Entity("account");
			account.addAttribute("avanade_wholesaleraccountno");
			var filter = new MobileCRM.FetchXml.Filter();
			filter.where("accountid", "eq", accountId);
			account.filter = filter;
			var fetch = new MobileCRM.FetchXml.Fetch(account);
			
			var props = entityForm.entity.properties;
				
	
			fetch.execute("Array", function (result) {
				if (result && result.length > 0)		{ 
					alert(result[0]);
                    props.asd_wholesaleraccountno = result[0];
                    alert(props.asd_wholesaleraccountno);
				}
			}, function (err) {
				MobileCRM.bridge.alert("Error during get WS account number info: " + err);
			}, entityForm);
		}
	}
}


At both alert I can see the correct value. But on the form I don't see the new value for the asd_wholesaleraccountno.

If I do the assign out of fetch.execute, I can see the new value.

Why I don't see the result in the necessary field?

Thanks advance.

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Resco CRM - assign value to field from field from another entity

    I found the solution:

    function onCustomerChanged(entityForm) {
    	if (entityForm.context.changedItem == "customerid") {
    		customerId = entityForm.entity.properties.customerid.id;  
    		if(entityForm.entity.properties.asm_wholesaleraccountno == null)
    		{
    			FetchAsDynamicEntity(customerId);
    		}
    	};
    }
    
    
    function FetchAsDynamicEntity(customerId) { 
    	var entity = new MobileCRM.FetchXml.Entity("account"); 
    	entity.addAttribute("asm_wholesaleraccountno"); 
    	entity.filter = new MobileCRM.FetchXml.Filter(); 
    	entity.filter.where("accountid", "eq", customerId); 
    	var dynamicEntity = null; 
    	var fetch = new MobileCRM.FetchXml.Fetch(entity); 
    	fetch.execute( "DynamicEntities", function (result) { 
    		if (typeof (result) != "undefined") { 
    			for (var i in result) { 
    				dynamicEntity = result[0]; 
    			}
    			MobileCRM.UI.EntityForm.requestObject( function (entityForm) { 
    				entityForm.entity.properties.asm_wholesaleraccountno = dynamicEntity.properties.asm_wholesaleraccountno; 
    			}, function (err) { 
    				alert(err); 
    				}, null ); 
    		} 
    	}, function (error) { 
    		alert("An Error Has occurred " + error); 
    	}); 
    }

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans