Function returning multiple values

SG23
Tera Expert

Hi Guys, I have a ask where Incident 'State' and 'Substate' values (Choice type) has to change based on the custom field 'u_task_opinion' value (String type). Please suggest how to make this possible using a function or so. Thanks.

 

1. Incident state will have substate values only when state is 'In Progress".

2. State value should remain same for some values of 'u_task_opinion'.

Eg: If ('u_task_opinion' == 'Make'){

      incident.state = 'New';

    } else if ('u_task_opinion' == 'Survey'){

      incident.state = 'In Progress';

     incident.u_substate = 'Message sent';

} else {

return;

}

1 ACCEPTED SOLUTION

Hi @SG23 

You can write a After Insert/Update Business Rule on Incident Task table like the one below.

(function executeRule(current, previous /*null when async*/ ) {
    var incGr = new GlideRecord('incident');
    if (incGr.get(current.incident)) {
        if (current.u_task_opinion == 'Make') {
            incGr.state = '1';
			incGr.update();
        } else if (current.u_task_opinion == 'Survey') {
            incGr.state = 'In Progress';
            incGr.u_substate = 'Message sent';
			incGr.update();
        }
    }

})(current, previous);

AnveshKumarM_0-1696473005986.png

 

AnveshKumarM_1-1696473020887.png

 

Please make sure for u_task_opinion field you are using backend values of Survey and Make.

 

Thanks,
Anvesh

View solution in original post

5 REPLIES 5

AnveshKumar M
Tera Sage
Tera Sage

Hi @SG23 

You can create a UI Policy and make it to work on onLoad too with condition like,

Task Opinion :: is One of :: Make, Survey

 

And in the Script tab of UI Policy for True script field add this code,

var task_opinion = g_form.getValue('u_task_opinion');

 

If ( tasktask_opinion == 'Make'){

      g_form.clearOptions('state');

      g_form.addOption('state', '1', 'New');

} else if ('u_task_opinion' == 'Survey'){

      g_form.clearOptions('u_sub_state');

      g_form.clearOptions('state');

      g_form.addOption('state', '2', 'In Progress);

      g_form.addOption('u_sub_state', 'Mesage Sent', 'Message Sent');

 

 

And in false script,

Add all the values you want in the state fields like above.

 

Thanks,
Anvesh

Okay sure, can this be done via script include ?

actually I want the Incident state/substate to get updated when the 'u_task_opinion' field on Incident task is set to different values (sorry this part is not added). Thanks.

Hi @SG23 

You can write a After Insert/Update Business Rule on Incident Task table like the one below.

(function executeRule(current, previous /*null when async*/ ) {
    var incGr = new GlideRecord('incident');
    if (incGr.get(current.incident)) {
        if (current.u_task_opinion == 'Make') {
            incGr.state = '1';
			incGr.update();
        } else if (current.u_task_opinion == 'Survey') {
            incGr.state = 'In Progress';
            incGr.u_substate = 'Message sent';
			incGr.update();
        }
    }

})(current, previous);

AnveshKumarM_0-1696473005986.png

 

AnveshKumarM_1-1696473020887.png

 

Please make sure for u_task_opinion field you are using backend values of Survey and Make.

 

Thanks,
Anvesh

Thanks for your help!