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

SAI VENKATESH
Tera Sage
Tera Sage

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
   
}

 

ca331.PNG

 

Thanks and Regards

Sai Venkatesh

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.

 

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

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