Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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
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
}

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

View solution in original post

7 REPLIES 7

Medi C
Giga Sage
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
}

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

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