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

Shree Nag
Tera Expert

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.

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?

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.remove('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.remove('state', 'work_in_progress', 'Work In Progress');


        }
    }
}

Community Alums
Not applicable

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!




Shree Nag
Tera Expert

All,

Thank you all for your time and help on this. I was able to get this going.