Restrict values of a choice field based on its current status
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2016 09:54 PM
Hello Experts,
I am trying to restrict the values of a choice field based on its current value. I understand we can use "Dependent Field" to restrict the values of based on the values of the other field but what I am trying to do here is little different.
I have a field named "Phase" and it has values viz. Concept, Define, Design, Build, Test, Release, Close.
The default value has been set to Concept. When Phase is set to Concept, it should only show Concept, Define and Close and when it is set to Define it should only show Concept, Define, Build and Close.
I am sure this must have been achieved already by your experts.
Appreciate your help.
Thanks
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2016 09:59 PM
Write an on load client script and use removeOption() function.
You can find an similar example in the 12.3 section of below link.
GlideForm (g form) - ServiceNow Wiki
Tthanks,
Mihir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2016 11:48 PM
Hi Srirao,
Use below onLoad client script:
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('Phase') == 'Concept')// For Concept use your database value and same for other states
{
g_form.removeOption('Phase', 'Design');
g_form.removeOption('Phase', 'Build');
g_form.removeOption('Phase', 'Test');
g_form.removeOption('Phase', 'Release');
}
if (g_form.getValue('Phase') == 'Define')
{
g_form.removeOption('Phase', 'Design');
g_form.removeOption('Phase', 'Test');
g_form.removeOption('Phase', 'Release');
}
}
Hope it will work for you.
Regards,
Swapnil
PS: Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2016 12:04 AM
Hi Srirao,
write onLoad Clietn script.
var onevalue = g_form.getValue('u_phase');
if (onevalue == 'Concept') {
g_form.removeOption('u_phase','Test');
g_form.removeOption('u_phase','Design');
g_form.removeOption('u_phase','Build');
g_form.removeOption('u_phase','Release');
}
else
onevalue='Define';
g_form.removeOption('u_phase','Test');
g_form.removeOption('u_phase','Design');
g_form.removeOption('u_phase','Release');
}
Regards,
Harshvardhan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2016 10:22 AM
Thanks for your replies Mihir 553931 Swapnil swapnilbhakare Harsh harshvardhansingh. Your solution did work and it restricts the values of the field at the time of loading (onLoad).
However, I want to apply the same restriction when the values in the field change i.e. when someone changes the value in Phase it should only show the restricted. So, I attempted to achieve this by copying the same script that I have written for onLoad and pasting it in a client script that is written for onChange. It works but for the first change only and the subsequent value changes have no effect.
abhi_r Michael.Fry ctomasi - Can you please shed some light on this?
Appreciate your help.