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
}

 


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

I still do need this fixed, sadly 

Ankur Bawiskar
Tera Patron
Tera Patron

@DeeMendoza 

myField is dependent on some other field.

share some more details?

Do you want your script to run for new record and existing record as well?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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


@Ankur Bawiskar wrote:

@DeeMendoza 

share some more details?

Do you want your script to run for new record and existing record as well?

Ideally this script should only run on existing records. You telling me that myField might be dependent on another field might be a useful clue