- 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 07:24 PM
Hi @Shree Nag
The functionality is working fine my PDI and attached is the image.
with configuration item:
Without Configuration item:
Script Image:
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 07:32 PM
Thank You for trying @SAI VENKATESH .
Here is the new update. I right clicked on the state choices, and made "Work In progress" inactive is true.
Here are my observations.
1. When there is no configuration item is selected, There is no Work in progress shown.
2. I enter the Configuration item "ABC", the Work in progress is shown in state field ( Yay !!!)
3. But when I remove the ABc configuration item, work in progress still shows in state.
We are almost there. The client script for Onchnage of Configuration item is:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 09:00 PM
I'm assuming in the script below that the Client Script is set to run onChange of the CI field:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//newValue contains the sys_id of the CI so we do NOT have to use g_form.getValue() to get it again
//and we want to do this regardless of "isLoading" or if the CI is blank
if (newValue == "sys_id of your CI") {
g_form.addOption("state", "work_in_progress", "Work In Progress", 1); //the "1" tells it where to show up in the list
} else {
g_form.removeOption("state", "work_in_progress");
}
}
Using a hard-coded sys_id is not the best way to do it, especially if there are multiple CIs that might need the state value.
And you would want to keep the "Work in Progress" in your list of choices for list views and reporting/filtering purposes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 07:58 PM
Ummm Looks Same on My side.
I will keep debugging.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 08:11 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.getValue('cmdb_ci');
alert(citem);
if (citem !== '') {
g_form.addOption('state', 'work_in_progress', 'Work In Progress');
} else {
g_form.removeOption('state', 'work_in_progress');
}
}
It is working as expected by you
Thanks and Regards
Sai Venkatesh