Need help on Inbound Actions Script

Bird1
Mega Sage

Currently, we're using Inbound Action: Update HR Case to update the ticket's state and comment. But we do have requirement if the HR case is already inactive, it should trigger the event to send auto reply message to sender.

 

Problem is I am not sure how to check the active true/false of HR case. I thought about using current.active == true and current.active == false but it seems the current.active in the script, it checks the email instead of HR case.

 

Can anyone please help?

 

gs.include('validators');

if (current.getTableName() == "sn_hr_core_case") {
    current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;

	if (current.active == true){ 

    if (email.body.assign != undefined)
        current.assigned_to = email.body.assign;

    if (email.origemail == current.opened_for.email || email.origemail == current.u_sender_email.toString())
	{
		var emailsubject = email.subject.toString().toLowerCase();
        if (emailsubject.indexOf("accepted") >= 0 && current.state == 20)
		{
			current.state = "3"; // closed completed
		}

        if (email.subject.indexOf("rejected") >= 0 && current.state == 20)
		{
            current.state = "18"; // work in progress
		}
    }
	}

	else if (current.active == false){
		
		if((email.origemail.toLowerCase().indexOf('abc.com') > -1) || (email.origemail.toLowerCase().indexOf('def.com') > -1))
		{
           gs.eventQueue('sn_hr_core.internalautoreply', current, email.origemail, current.number);
		}
		else if((email.origemail.toLowerCase().indexOf('abc.com') == -1) && (email.origemail.toLowerCase().indexOf('def.com') == -1))
		{
           gs.eventQueue('sn_hr_core.externalautoreply', current, email.origemail, current.number);
		}
	}

    current.update();
}

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Bird1 

try this and use toString()

gs.include('validators');

if (current.getTableName() == "sn_hr_core_case") {
    current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;

	if (current.active.toString() == 'true'){ 

    if (email.body.assign != undefined)
        current.assigned_to = email.body.assign;

    if (email.origemail == current.opened_for.email || email.origemail == current.u_sender_email.toString())
	{
		var emailsubject = email.subject.toString().toLowerCase();
        if (emailsubject.indexOf("accepted") >= 0 && current.state == 20)
		{
			current.state = "3"; // closed completed
		}

        if (email.subject.indexOf("rejected") >= 0 && current.state == 20)
		{
            current.state = "18"; // work in progress
		}
    }
	}

	else if (current.active.toString() == 'false'){
		
		if((email.origemail.toLowerCase().indexOf('abc.com') > -1) || (email.origemail.toLowerCase().indexOf('def.com') > -1))
		{
           gs.eventQueue('sn_hr_core.internalautoreply', current, email.origemail, current.number);
		}
		else if((email.origemail.toLowerCase().indexOf('abc.com') == -1) && (email.origemail.toLowerCase().indexOf('def.com') == -1))
		{
           gs.eventQueue('sn_hr_core.externalautoreply', current, email.origemail, current.number);
		}
	}

    current.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar  - Thanks, I have tried to update my script but it doesn't work.

 

The thing is based on my original script, the active = true HR case got triggered by Inbound Action properly (add comment, accept/reject the case) but the active = false doesn't trigger.

 

I am not sure that 

  • current.active in the Inbound Action script refer to the Target record?
  • I have verfied the spelling of event name, it's correct and it's created under Human Resources: Core scope, HR Case [sn_hr_core_case] table.,  not sure why it's not triggered.

@Bird1 

yes current object refers to target record

I believe system is not considering to execute inbound action when record is active=false

check in docs

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar  - Actually my original script working fine but due to I do testing the inbound action in DEV instance but the notification email, I force set "From" and "Reply to" Production instance, so when I replied the email, I did not realized that I was replying to Production instead of DEV.

 

After I manually reply email to DEV instance, the Inbound Action script is working fine both active = true and false.