We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Client Script for choices in Form being overwritten by something else

DeeMendoza
Tera Contributor

Hi everyone!

I had written an onLoad client script for an incident form (specifically the Security Incident Response form, but I don't think that matters)
-where the script removes some choices in a dropdown field depending on the value of another field.


At first, it works fine
, but after one second, ALL the choices come back, undoing the work of the script. I have looked at the Client Script table, UI Actions table, and even at some Data Policies and couldn't find a **bleep** thing to that might affect and override my script for this specific dropdown field.

 

Does anyone else know where I can look to see if anything else is affecting this field? Or are those three tables the only places?

Script below in case if needed:

function onLoad() {
    //var group = g_form.getDisplayBox('assignment_group').value;
    var group = g_form.getValue("assignment_group");

    if (group == "sysid of group") { 
        g_form.removeOption('myField', '3');
        g_form.removeOption('myField', '13');
        //alert("The assignment group is xyzgroup!");

    }
}

 

 

1 ACCEPTED SOLUTION

Medi C
Giga Sage

Hi @DeeMendoza,

 

Could you try the following:

function onLoad() {
    setTimeout(function() {
        var group = g_form.getValue("assignment_group");
        if (group == "sysid of group") { 
            g_form.removeOption('myField', '3');
            g_form.removeOption('myField', '13');
        }
    }, 1000); // Adjust timing as needed
}

 


Thanks & Best regards,
Medi

View solution in original post

7 REPLIES 7

Medi C
Giga Sage

Hi @DeeMendoza,

 

Could you try the following:

function onLoad() {
    setTimeout(function() {
        var group = g_form.getValue("assignment_group");
        if (group == "sysid of group") { 
            g_form.removeOption('myField', '3');
            g_form.removeOption('myField', '13');
        }
    }, 1000); // Adjust timing as needed
}

 


Thanks & Best regards,
Medi

I like the idea but unfortunately my script still gets overridden

It looks like this will have to be what I do, as "band aid" as it may be. Thank you Medi

Prasad Pagar
Mega Sage

Hi @DeeMendoza ,

 

Did you find the fix or you still need help with this?

 

Thank you

Prasad