Inbound action using current

Mark118
Tera Contributor

Hello all

I am trying to set an inbound action to stop updating a case when the case is closed. I have read various forum posts and believe that I have this setup right, however every time the reply comes into the instance I am receiving. 

"Update HR Payroll Case : did not create or update sn_hr_core_case_payroll using current"

My inbound action has an Action Type == Record Action

Script:

gs.include('validators');

if (current.getTableName() == "sn_hr_core_case_payroll") {
	var hrPayroll = current;
	if(hrPayroll == false){
		gs.log('>>>>>>>>>>MArk log');
		hrPayroll.comments('User replied to a Closed incident. Auto-reply notification sent to the user');
		hrPayroll.update();
	}
    hrPayroll.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
    if (email.body.assign != undefined)
        hrPayroll.assigned_to = email.body.assign;
    hrPayroll.update();

}

Thanks in advance

 

4 REPLIES 4

Marcin20
Mega Guru

Hi Mark,

 

I'm not sure about

if(hrPayroll == false){

I would propose checking whether the case is closed, a condition similar to

if (hrPayroll.getValue('state') == '9')  {   //please adjust the name of the field and the value, I have taken it from the incident

 

Best Regards,

Marcin

 

If my answer helped you in any way, please mark this answer as helpful and correct.

 

Mark118
Tera Contributor

Thanks for the reply Marcin,

I managed to get this working in the end thanks to your guidance and some serious head scratching and loads of testing, 

this is what I ended up with: 

if (current.getTableName() == "sn_hr_core_case_payroll") {
    if (current.state == 3) {
        current.work_notes = 'User replied to a Closed incident. Auto-reply notification sent to the user';
        gs.eventQueue('sn_hr_core.hr_case.closed', current, 'hello', gs.getUserName());
    } else {
        current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
        if (email.body.assign != undefined)
            current.assigned_to = email.body.assign;
    }
    current.update();
}

Abhinay1
Giga Expert

Hello Mark,

"var hrPayroll = current;" what are you trying to do here? ---- Remove this statement

Next line, "if(hrPayroll == false){", here, I believe you want to check the active state, use "if(current.active == false){"

 

below every where, replace "hrPayroll" with "current"

current.comments('User replied to a Closed incident. Auto-reply notification sent to the user'); current.update();

}

current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;

if (email.body.assign != undefined)

current.assigned_to = email.body.assign;

current.update();

}

 

Regards

Community Alums
Not applicable

Please try to use:

if(hrPayroll.active == false)