How to remove choices in a field?

Karthik Reddy T
Kilo Sage

Hi All,

I want to remove the choice   in the state field for an ITIL user.

My Requirement.

If state is new : All choices should display.

If In progress: Display only In progress, Cancelled, On hold.

If On Hold: Resolved,In progress, cancelled.

Can any one help me .

Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.
1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee
4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Karthik,



This can be done via Client script. Based on the condition you have to add or remove the choice values. Please refer.


https://www.servicenowguru.com/scripting/client-scripts-scripting/removing-disabling-choice-list-opt...


http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#gsc.tab=0


Thanks Pradeep,



Its working now.


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

Rajesh Mushke
Mega Sage
Mega Sage

Hello



i hope this could be helpful :


removeOption

void removeOption(fieldName, choiceValue)


Removes a specific option from a choice list.
Note: (Versions prior to Eureka) When items are removed from a choice list by a Client Script, Google Chrome and Apple Safari will still display those items. When one of these web browsers is used, the "removed" items will be displayed as read only in the choice list and they cannot be chosen.
Parameters:
fieldName - specifies the field.
choiceValue - specifies the value stored in the database as a choice.
Returns:
void
Example: Remove the '1' Option from the Priority Field
g_form.removeOption('priority', '1'); 
Example: Remove the 'Closed' State Option if the User is not an Admin
function onLoad() { var isAdmin = g_user.hasRole('admin'); 
var incidentState = g_form.getValue('incident_state');
if (!isAdmin && (incidentState != 7)){ g_form.removeOption('incident_state', '7'); } }




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Shishir Srivast
Mega Sage

Hi Karthik,



You want to set the state field based upon the state field value? that can be done with onChange() client script,


How about this condition If On Hold: Resolved,In progress, cancelled. ??



Something like this should help,



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


if (isLoading || newValue === '') {


return;


}


//Type appropriate comment here, and begin script below


if(g_user.hasRole('admin'))


{


if(g_form.getValue('state') == '2')


{


g_form.clearOptions('state');


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


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


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


}


}


}