- 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:31 PM
Ahh ! Now with the latest script updated, Thank you.
It shows Work in progress for any configuration item selected.
If the configuration is empty, work in progress not seen.
I need to add in the script, If the Configuration Item contains anything starting with "ABC", show work in Progress.
- 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-03-2024 06:01 AM
Hello Sai,
That worked perfect!!! Thanks for continuous help !.
Appreciate it .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 07:22 PM
Hi @Shree Nag
Try below script and modify it according to your correct values.
var stateField = ‘state’; // Reference to the state field
var workInProgressValue = ‘-5’; // The value corresponding to “Work In Progress”
// Check if the configuration item has a value
if (newValue) {
// Add “Work In Progress” option if it’s not already there
if (!g_form.getOption(workInProgressValue)) {
g_form.addOption(stateField, workInProgressValue, ‘Work in Progress’);
}
} else {
// Remove “Work In Progress” choice if the CI field is empty
g_form.removeOption(stateField, workInProgressValue);
// Ensure that the state field is cleared if it holds the “Work In Progress” value
if (g_form.getValue(stateField) == workInProgressValue) {
g_form.setValue(stateField, ‘’);
}
}
}
please mark this Helpful and Accepted Solution if this helps you. Your action will help me and the community in understanding same requirements.
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 08:19 PM
Make Sure your using choice value of State Work in Progress while adding choice and removing