Onload client script not working as expected on "Service Operations Workspace"

Ansh Mahajan
Tera Contributor

I wrote an onload client script on "incident" table to make remove some choices in the state field when the record is in in progress. The script is working fine on "Agent Workspace" but it is not working as expected on "Service Operations Workspace". Basically the choices are not getting updated. 

For example:- When the record is in "On Hold" state only option available in the state field should be "in progress". but when we move from "On Hold" to "in progress" the available options should be "in progress" , " On Hold" and "Resolved" but the options available are "in progress"  and " On Hold". 

 

to make it work we have to reload the entire page manually after updating the record. 

 

 how can we make it work as soon as someone will save/update the form.

 

5 REPLIES 5

Voona Rohila
Kilo Patron
Kilo Patron

HI @Ansh Mahajan 

Can you share the onLoad script.


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Community Alums
Not applicable

Hi @Voona Rohila 

 

I won't be able to share the script but its just a simple on load client script which have else if conditions from which we are removing the state choices accordingly.

 

Regards,

Ansh Mahajan

Hi @Community Alums 

Looks like the issue is in the client script,You can share some sample code by changing fields

Sample :

    if (newValue == 'x')
	{
        g_form.clearOptions('company'); //clear all the options
        g_form.addOption('company', 'pepsi', 'Pepsi', 1); //add the necessary options.
        g_form.addOption('company', 'cocacola', 'CocaCola', 2);//add the necessary options.
    }
	else if (newValue == 'y')
	{
        g_form.clearOptions('company');
        g_form.addOption('company', 'apple', 'Apple', 1);
        g_form.addOption('company', 'samsung', 'Samsung', 2);
    }

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Hi @Voona Rohila ,

 

Yes it is working fine but does it is recommended as ServiceNow technical best practice ?

 

Regards

Ansh Mahajan