- 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 01:08 PM
Hi @Shree Nag
You can use on change client script with onChange of Configuration item.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue!=''){
g_form.setValue('state',2);
}
//Type appropriate comment here, and begin script below
}
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 01:21 PM
Thank you for the quick reply.
I updated my script. Your post was helpful in getting the State field setting to "work in Progress". But we need to just populate/add the choice of "Work In Progress" to state field. The user will select from the list.
Also when the configuration item is not ABC, The state should not display " work In Progress" at all. Right now it does.
For this
I added a UI Policy. Added condition as If configuration Item contains "ABC".
I wan to add UI policy action under this to select Field name "State" to display "Work In Progress" , Only when the configuration item is selected. But Im unable to select to value level .
How do I narrow down for the value of "work In Progress" to display only when certain Configuration is selected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 01:27 PM
Hi @Shree Nag
You can use client script for this,
var ci = g_form.getValue("cmdb_ci");
if (ci == "<sys_id of ABC ci>") {
g_form.addOption('state','Work In Progress','-5');
} else {
g_form.removeOption('state','Work In Progress','-5');
}
If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.
Best Regards,
Krushna Birla
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 01:28 PM - edited 07-02-2024 01:53 PM
Hi @Shree Nag
You can 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 || newValue === '') {
return;
}
if (newValue !== '') {
g_form.addOption('state', 'work_in_progress', 'Work In Progress');
}
else{
g_form.removeOption('state', 'work_in_progress', 'Work In Progress');
}
}
Thanks and Regards
Sai Venkatesh