Client Script to Set values When Incident State changes to closed for a particular caller

Michael Nash2
Mega Expert

I need assistance with a Client Script to Set values When Incident State changes to closed for a particular caller.

 

I need to set the fields as follows when the Incident state changes to closed.

Close Code - Closed/Resolved by caller

Close Notes - Closed by Caller (Joe Soap)

Closed by -  Caller (Joe Soap)

9 REPLIES 9

Bhawana Upreti
Tera Guru

Hi,

Write a onChange client script field name would be state.

and here is the script please change the field value accordingly if needed.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}


var caller = g_form.getReference('caller_id');
var stateValue=g_form.getValue('state');
alert(stateValue);
if(newValue==3||newValue==7)
{
g_form.setValue('close_code','Closed/Resolved by Caller');
g_form.setValue('closed_by',caller.name);
g_form.setValue('close_notes',"Closed by "+caller.name);
}
}

 

Thanks.

Sujit Poojari1
Tera Contributor

Hi Michael,

You may also write a Business Rule, in case you want to execute the actions after the incident state is saved/updated as "Closed".

In the BR, you will define the script as below:

Execute the BR on 'Before - Update' or 'After - Update'

Advanced tab: check "Advanced" checkbox to view this tab
Conditions:
current.caller_id = gs.getUserID() && current.state.changesTo(7)    //To check if the user closing the incident is the Caller, and state is closed (modify the state value if needed)

Script:

current.close_code = 'Closed/Resolved by Caller';
current.closed_by = current.caller_id;
current.close_notes = "Closed by ( "+current.caller_id.name+" )";

Note: In case of After-update BR, you will need to add current.update() at the end of the script.

Thanks and Regards,
Sujit Poojari

 

Michael Nash2
Mega Expert

Thanks guys,

 

Thanks, this seems to work but it is giving me a pop up message, see attached. (Don't need this )

 

I also need this script for a single user sys ID (bdf7f0d5db19874009cffd141d961968)

 

maybe its best to mention this is a call being updated by the Application Managers API call.

Hi Michael,

Reason for the alert message was just a single line alert(stateValue); remove this line. Every time the user is Joe Soap.this script will run. Please replace your script with the given one.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller = g_form.getReference('caller_id');
var stateValue=g_form.getValue('state');
if(caller.name=='Joe Soap' && (newValue==3||newValue==7))
{
g_form.setValue('close_code','Closed/Resolved by Caller');
g_form.setValue('closed_by',"bdf7f0d5db19874009cffd141d961968");
g_form.setValue('close_notes',"Closed by Joe Soap");
}
}