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...
Answered

Use JS and IsDirty to get all changed fields on a form in Dyn356 in readable format

(0) ShareShare
ReportReport
Posted on by 161

Hi,

I am using isDirty method to detect all changes on a Form in Dyn365 made by a user.

I can use   var dataXml = formContext.data.entity.getDataXml(listofDirtyAttributes) to get a list of dirty fields in XML format.

My fist question is. How do I detect optionset and lookup fields while getting all dirty fields?

Second question.

Is it possible to get Label(Display Name) of fields.

Here is a function I use.

if (formAttributes != null) {
        for (var i in formAttributes) {
            if (formAttributes[i].getIsDirty()) {
                listofDirtyAttributes += formAttributes[i].getName() + "\n";  
                formAttributes[i].controls.forEach(        
            control => control.addNotification({              
                messages: ['Changed'],
                notificationLevel: 'RECOMMENDATION'                      
            })          
        );                  
                   
            }
        }
    }

Thank you.

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I composed a quick script that you can check:

    var formContext = executionContext.getFormContext();
    formContext.data.entity.attributes.forEach(function(a){
    	if (!a.getIsDirty()){
    		return;
    	}
    
    	console.log(a.controls[0].getLabel());
    	console.log(a.getAttributeType()); 
    	console.log(a.getValue())
    });

  • Kahspot Profile Picture
    161 on at

    Hello a33ik 

    Thank you for the provided solution but still can't retrieve option set text value and labels for dirty fields.

    Regards

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    If you want to get the optionset text value you will have to use the following code for the attribute - a.getText() instead of a.getValue().

    Still not sure what you meant by "get labels" - can you please clarify what was meant?

  • Kahspot Profile Picture
    161 on at

    Hello a33ik

    Thanks . I have already tried a.getText() before but gotten an error: a.getText() not a function.

    By a field label I mean a field's 'Display Name'. Sorry for the confusion.

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Can you please provide your code?

    In regards the label I believe you meant "Display Name" of the lookup attribute. In this case the following should help:

    console.log(a.getValue()[0].name);

  • Kahspot Profile Picture
    161 on at

    Hello a33ik ,

    Im using my test environment.  A Java script is pretty simple.

    function onChangeSave(executionContext) {

      var formContext = executionContext.getFormContext();

      var formAttributes = formContext.data.entity.attributes.get();

      var listofDirtyAttributes;

     var changedField = formContext.getAttribute("test_changedfields");

    if (formAttributes !=null){

       formContext.data.entity.attributes.forEach(function(a){

         if (a.getIsDirty()){  

            listofDirtyAttributes +=  a.controls[0].getLabel() + "\n" +  a.getAttributeType() + "\n" + a.getValue()+  "\n" +a.getText() +  "\n" ;

         }      

       return;

       });

     }

     var dataXml = formContext.data.entity.getDataXml(listofDirtyAttributes);

    changedField.setValue(dataXml);

    }

    Im trying to get a readable output . Please see the screenshot below.

    pastedimage1685379617043v2.png

    Here is what I call 'Label'. Please see the screenshot below.

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Not sure what you're doing in those lines:

    var dataXml = formContext.data.entity.getDataXml(listofDirtyAttributes);

    changedField.setValue(dataXml);

    If you want to set the changedField to your value just use

    changedField.setValue(listofDirtyAttributes);

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
Martin Dráb Profile Picture

Martin Dráb 49 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans