Help with Client script When a Particular Configuration Item is choosen

Shree Nag
Tera Expert

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

 

1 ACCEPTED SOLUTION

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

View solution in original post

24 REPLIES 24

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.

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

Hello Sai,

That worked perfect!!! Thanks for continuous help !.

 

Appreciate it .

Deepak Shaerma
Kilo Sage

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

Madankumar N1
Tera Contributor
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    // If the form is loading or the new value is empty, do nothing
    if ( newValue === '') {
        return;
    }
   var configurationItem=g_form.getValue("configuration_item");
var state=g_form.getValue("state");
if(state!="work_in_progress"){
    if (configurationItem == 'cisysid') {
        g_form.addOption('state''work_in_progress''Work In Progress');
    }
    else{
          g_form.remove('state''work_in_progress''Work In Progress');

 

    }
}
}
Make Sure your using choice value of State Work in Progress while adding choice and removing