- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2024 04:29 AM
Hi All
I have a small query.
I am writing a onChange client script. my requirement is if "model_category" = "computer" then I need to remove a option from the "substatus" field in the alm_hardware table. model_category is a read-only reference field.
Below is my script.
onChange client script: is not working.
field: State
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2024 10:55 AM
@Prasnajeet1 , I just checked in my PDI so in your case in alm_hardware the substate is a dependent field on state so i tried onchange of state checked model category the choice value is not getting removed or getting added you can remove dependent value in substate but it will change for every model category.
if it is a dependent value then removeOption will work on onload but not on onchange so you might have to write a combo of both or as workaround if you know on which State choice you want to remove the option write it in onload client script only.
Servicenow
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0681253
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2024 09:29 AM
Hi @Prasnajeet1
For me it's working . could u please retry and let me know .
Scenario : When Caller is "Abel Tuter" then Remove "Chat" Option from Channel.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if (g_form.getValue('caller_id') == '62826bf03710200044e0bfc8bcbe5df1') { // Caller = "Abel Tuter"
alert('test');
g_form.removeOption('contact_type', 'chat');
}
}
CS :
O/P :
Now You can see the Caller is "David Milller" and Channel has same "Chat" option.
after Caller changes to "Abel Tuter" , "Chat" option is not available in Channel.
Note : If you are trying to remove a specific choice value from a variable , then kindly go through these links :
Link 2 : https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0678206
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Subhashis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2024 10:52 AM
Hi @Prasnajeet1
Your script seems to be Okay. Have you selected correct field name? I think it should be Model Category instead of State. Try changing UI Type to All. And also, you can give a try to following script-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var modelCategory = g_form.getDisplayValue('model_category');
if (modelCategory == 'computer') {
g_form.removeOption('substatus', 'lease_return');
}
}
Please mark my answer helpful and correct.
Regards,
Amit