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 :
Customer experience | Sales, Customer Insights,...
Answered

Dynamically Pass a attribute/field logical name to a JavaScript resource onchange of that attribute/field

(0) ShareShare
ReportReport
Posted on by 2,175

Hi all,

Just a quick one. I've got a JavaScript web resource that updates fields of a related entity record from a lookup field on the primary entity record. There are 2 fields that need updating/syncing across the related entity records.

I've then set the web resource to load on change of each of the 2 fields on the primary entity record. The problem is that how I've got the javascript set is that it will update both fields everytime a single field is changed as the script statically sets the attribute values.

What I thought about is whether there's a way to dynamically pass the attribute name as a variable so that when that attribute changes value I only need to update the one field that's changed as opposed to both of them everytime.

As an example of the below code:

function attributeTest (executionContext){
var formContext = executionContext.getFormContext();
// You can see I'm statically getting the attribute one value by inputting the logical name of that attribute
var attributeOneValue = formContext.getAttribute("new_attributeone").getValue();
// I want to see if it's possible to pass the "new_attributeone" logical name as a parameter or variable so that I can dynamically get values of the field that's being changed.
}

Kind regards,

Mike

I have the same question (0)
  • Verified answer
    Abhishek Dhoriya Profile Picture
    1,013 on at

    Hi Mike,

    This is can be achieved via. simple configuration and few code changes as mentioned below.

    Step 1: Update your Function to revive one more parameter apart from executionContext like below.

    function attributeTest (executionContext, paramOne){
    
    var formContext = executionContext.getFormContext();
    // You notice we have added another parameter to function, we are using below
    
    var attributeOneValue = formContext.getAttribute(paramOne).getValue();
    
    }

    Step 2) Pass that respective dynamics parameter Value Dynamically from Front End

    while calling this method from different fields . In this case it is the attribute name it self like new_attributeone and new_attributetwo

    2019_2D00_12_2D00_04_5F00_16_2D00_17_2D00_20.png

    I hope this answers your query, if you find this useful mark this reply as Verified Answer.

    And always feel free to post back if more assistance is needed.

    Regards,

  • Suggested answer
    Roma Gupta Profile Picture
    725 on at

    Hi Mike

    You can also set a flag in case you don't want to provide any extra parameter but that will increase checks & line of code.

    Regards

    Roma

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans