Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Form screen does not recognize field value changes in client script as record updates.

MugTm09
Tera Guru

Form screen does not recognize field value changes in client script as record updates.

I defined a ClientScript to change the items on the incident screen in accordance

with changes to other items.(onchange script)

Unfortunately, the screen does not seem to detect other field changes

made by the script when you revert the field that was manipulated.

 

Now, if I manually restore the value from what was changed by the client script,

the form screen still recognizes it as "changed" even though it has been restored.

 

This is an unnatural behavior,

so if anyone has any tips or ideas on how to solve this, I would appreciate your help.

1 ACCEPTED SOLUTION

MugTm09
Tera Guru

Hi, Everyone.


I have confirmed that the script below works on the standard UI16 interface but does not work in Workspace.
The fact that it does not work in Workspace is by design, as indicated KB0855260 .

Furthermore, I was unable to find any method or property in Workspace that allows detecting whether changes have occurred.

However, as shown Detecting Form changes in CSM/Agent Workspace - ServiceNow Community,
it seems possible to detect updates.

If anyone knows of a logic that can detect changes in Workspace,

I would greatly appreciate it if you could continue investigating.

At the very least, if you're using the standard UI16 interface,

the implementation below should be helpful.

    var targetKey = "problem.u_custom_choice";
    alert("Before:" + JSON.stringify(g_form.modifiedFields));

    Object.keys(g_form.modifiedFields).forEach(function(key) {
        if (key == targetKey) {
            delete g_form.modifiedFields[key];
        }
    });
    alert("Clean:" + JSON.stringify(g_form.modifiedFields));

    g_form.modifiedFields['problem.u_custom_choice'] = true;
    alert("After:" + JSON.stringify(g_form.modifiedFields));

Regards. 

View solution in original post

7 REPLIES 7

Hi @MugTm09 ,

 

It seems you didn't implement g_form.modifiedFields correctly as below post by Ravi mentioned 

g_form.setValue('category', 'hardware'); g_form.modifiedFields = g_form.modifiedFields.filter(function(field) { return field !== 'category'; });

Try it out.

 

Did you got a chance to go through the reference mentioned in my previous post.

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!

Hi, @Bhimashankar H .

This script doesn't work because `.filter` is not a valid function.

 

Based on the hint I received from @Ravi Gaurav , 

I confirmed that the items are controlled via a JSON object.

However, modifying this JSON object only works on standard UI16 screens

and does not function in Next Experience environments such as Workspace,

so it was not a viable solution. (It is effective in some cases.)

var str = '{"problem.u_custom_choice":true}';
g_form.modifiedFields = JSON.parse(str);



MugTm09
Tera Guru

Hi, Everyone.


I have confirmed that the script below works on the standard UI16 interface but does not work in Workspace.
The fact that it does not work in Workspace is by design, as indicated KB0855260 .

Furthermore, I was unable to find any method or property in Workspace that allows detecting whether changes have occurred.

However, as shown Detecting Form changes in CSM/Agent Workspace - ServiceNow Community,
it seems possible to detect updates.

If anyone knows of a logic that can detect changes in Workspace,

I would greatly appreciate it if you could continue investigating.

At the very least, if you're using the standard UI16 interface,

the implementation below should be helpful.

    var targetKey = "problem.u_custom_choice";
    alert("Before:" + JSON.stringify(g_form.modifiedFields));

    Object.keys(g_form.modifiedFields).forEach(function(key) {
        if (key == targetKey) {
            delete g_form.modifiedFields[key];
        }
    });
    alert("Clean:" + JSON.stringify(g_form.modifiedFields));

    g_form.modifiedFields['problem.u_custom_choice'] = true;
    alert("After:" + JSON.stringify(g_form.modifiedFields));

Regards.