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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Suggested Answer

How to change one lookup field on change of another?

(0) ShareShare
ReportReport
Posted on by 134

On change of District (lookup field) of Work Order, we want change on Price List( Lookup Field) of Work Order, how to achieve this?

  • Ali Khan Profile Picture
    1,380 on at

    There is no out of the box field 'District' on the Work Order. Is it a custom field? You can use Javascript for auto-setting any field based on business logic.

  • Suggested answer
    antc Profile Picture
    2,911 on at

    You could go with Flow, plugin or javascript.

    Below is an example of JavaScript that you would attach to OnChange Event of the District lookup field. The names of the columns or your lookup are likely different and I can't recall if there are any issues setting pricelist however the basic structure should be right.

    function getsetLookupDetails(executionContext)
    {
    	// Getting Form Context
    	var formContext = executionContext.getFormContext();
    	// Getting the value of District
    	var districtId = formContext.getAttribute("new_district").getValue();
    	// Getting the GUID District
    	var Id = districtId[0].id;
    	// Getting Name of the District
    	var Name = districtId[0].name;
    	// Getting Entity Name of District
    	var EntityType = OwnerId[0].entityType;
    	// Retrieve the priclist
    
        if (FormType == 1) {
            Xrm.WebApi.retrieveMultipleRecords("pricelist", "?$select=name,pricelevelid").then(  
            function success(result) {
    
                for (var i = 0; i < result.entities.length; i  ) {
                    var pricelistId = result.entities[i]["pricelevelid"]; // id pricelist
                    var pricelistName = result.entities[i]["name"]; // name of pricelist
                    var pricelistEntity = "pricelist"; // Should be priclist entity name 
                    if(pricelistName == Name) // If Name of district name of pricelist otherwise use some other logic to check mname
                    {
                        formContext.getAttribute("msdyn_fieldservicepricelistitemid").setValue([{ id: pricelistId, name: pricelistName, entityType: pricelistEntity }]);
                    }
                }
            }); 
        }
    }

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Travis South Profile Picture

Travis South 54

#2
11manish Profile Picture

11manish 37 Super User 2026 Season 2

#3
ParthPatel249 Profile Picture

ParthPatel249 33

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans