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

Slava Savitsky
Giga Sage

If you post what you have already tried, you are likely to get your issue resolved faster.

Krushna R Birla
Kilo Sage

Hi @Shree Nag 

 

You can use onChange client script to achieve this, select configuration item as a field name for this client script.

 

var ci = g_form.getValue("cmdb_ci");
if (ci == "<sys_id of ABC ci>") {
    g_form.setVisible('state', true);
    g_form.setValue("state", "-5");
} else {
    g_form.setVisible('state', false);
}

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

 

 

 

 

Shree Nag
Tera Expert

 

I updated my script. @SAI VENKATESH  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.

here is what I did So far.

1.I added the Work In Progress in Choice list on incident form.

2. I added a UI Policy. Added condition as, If configuration Item contains "ABC".

3. I want 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.

Hi @Shree Nag 

 

I provided the updated script please look into it.

 

 

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

Shree Nag
Tera Expert

Hello All,

Thank you all for pitching in. I updated the client script with both @Community Alums and @Krushna R Birla's script. But I still see the work in progress state without even choosing any configuration item. Here are few pics attached

Hopefully this will shed some light and help me resolve the issue.