Is it expected behavior for a List Collector onChange script not to trigger when a value is reselect

SiddeswaraJ
Tera Contributor

Hi Community,

 

I am trying to understand whether the following behavior is expected for a List Collector variable.

In my List Collector, there is an option called **"Show Task Status"**. When a user selects **"Show Task Status"**, an on Change client script is triggered and displays info message to the user.

The behavior I am seeing is:

1. User selects **"Show Task Status"**.

2. The on Change script executes and the information is displayed as expected.

3. User removes/deselects **"Show Task Status"** from the List Collector.

4. User selects **"Show Task Status"** again.

5. The on Change script does not appear to execute again, and the information is not displayed.

My question is whether this is expected platform behavior for List Collectors. When a value is removed and then selected again, should ServiceNow treat it as a new change and trigger the onChange script again?

I am trying to determine whether this is a standard List Collector limitation/behavior or if I should investigate the implementation further.

Any documentation, KB articles, or clarification would be appreciated.

 

Thank you.

 

Ignore

 

1 ACCEPTED SOLUTION

@SiddeswaraJ 

yes this is expected behavior

For a List Collector, the value is a comma-separated list of sys_ids. If you remove and re-add the same item, and the resulting string is the same as before, the platform may treat it as no change and not fire onChange

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron

@SiddeswaraJ 

share your script here along with screenshots

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }
    if (g_form.flag_match == "true") {
        return;
    }
    var targetSysId = 'f1b24e4cc33cd2903ca79dc905013168';
    var existsNow = newValue.indexOf(targetSysId) > -1;
alert("onchange running");
    // Trigger only when newly added
    if (existsNow) {
        if (g_form.flag_match != "true") {
        g_form.addInfoMessage("it to this request");
        g_form.flag_match = "true";
        }
     }else{
        g_form.flag_match = "false";
    }

}
does on change script is executed for selecting same value second time after dis-selecting it

@SiddeswaraJ 

yes this is expected behavior

For a List Collector, the value is a comma-separated list of sys_ids. If you remove and re-add the same item, and the resulting string is the same as before, the platform may treat it as no change and not fire onChange

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader