add option in client script

jobin1
Tera Expert

On load of sc_req_item i need to add one option in the state field which is already available in the choice list and is disabled for now for some reason so will  the below code will work for adding it back ?

 

g_form.addOption('state','104');

10 REPLIES 10

Hi @jobin1 ,

addOption accepts three arguments

g_form.addOption('state', '104', 'Nameofthestate');

 

Best Regards
Aman Kumar

it's working but once the state is saved with that value its again immediately updates to none why so?

jaheerhattiwale
Mega Sage

@jobin1 You can add the below script, which includes the choice label as well

 

g_form.addOption('state',104,'<CHOICE LABEL HERE>');

 

BTW if the field is disabled you can never use that option which you added from script.

So you need to make state field editable first.

 

Please mark correct answer if this answers your question.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

jobin1
Tera Expert

how we can arrange the order its coming at last position

@jobin1  Add the 4th parameter as 0

g_form.addOption('state',104,'<CHOICE LABEL HERE>', 0);

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023