- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 12:59 PM
Hello,
I have a requirement to make a state value( "Work In Progress" ) visible only when a particular configuration item is chosen on an incident form.
If a user choses "Abc" in configuration item on an incident form, Work In progress state ( value =-5) value should show up in State field.
Can you all help me with the client script for this please.
Appreciate your response.
-Thanks
Shree
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 08:53 PM
Hi @Shree Nag
Can you try the below script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// If the form is loading or the new value is empty, do nothing
if (isLoading) {
var citem = g_form.getValue('cmdb_ci');
return;
}
var citem = g_form.getDisplayBox('cmdb_ci').value;
alert(citem);
if (citem !== '' && citem.startsWith('Thi')) { // updated the code as per your need
g_form.addOption('state', 'work_in_progress', 'Work In Progress');
} else {
g_form.removeOption('state', 'work_in_progress');
}
}
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 08:34 PM
Thank You @Madankumar N1 for the script.
There is no particular sys ID for that config item. If the users selects Configuration item anything containing "ABC", then I need display the Work In progress.
Could you please help with your modified script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 11:18 PM
Scenario 1:On change configuration Item if CI name contains "ABC" then we need to hide work in progress option and if name not contains ABC then we need to show working in progress?
Scenario 2: If configuration item is empty they need to hide Work in progress choice in state value is that correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 11:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2024 04:14 AM
Hi @Shree Nag,
you can try below script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// If the form is loading or the new value is empty, do nothing
var state = g_form.getValue("state");
if (newValue === '' && state != "work_in_progress") {
g_form.removeOption('state', 'work_in_progress', 'Work In Progress');
return;
}
var configurationItem = g_form.getDisplayBox('cmdb_ci').value;
if (state != "work_in_progress") {
if (configurationItem.indexOf("ABC") > -1) {
g_form.addOption('state', 'work_in_progress', 'Work In Progress');
} else {
g_form.removeOption('state', 'work_in_progress', 'Work In Progress');
}
} else { // Added else block to clear state field, if already Work in progress state was selected.
g_form.removeOption('state', 'work_in_progress', 'Work In Progress');
}
}
If my response is useful please mark helpful or accept as a solution.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2024 06:01 AM
All,
Thank you all for your time and help on this. I was able to get this going.