The CreatorCon Call for Content is officially open! Get started here.

sys_email instance variable

AdriàM
Tera Contributor

I'm having a problem where I try to get the value of the instance variable from a business rule on Insert of the table sys_email when an email is recieved.
I found that the value isn't defined after some updates, so I changed the business rule, but the sys_email is updated 4 times.
I'd like to know why ServiceNow does so many updates on the sys_email registry.

 
(function executeRule(current, previous /*null when async*/) {
	if(current.instance) gs.log("id ritm: "+current.instance.toString());
	else gs.log("INSTANCE NOT ASSIGNED");
})(current, previous);
1 ACCEPTED SOLUTION

M Iftikhar
Giga Sage

Hi @AdriàM ,

sys_email records go through multiple system updates as inbound processing assigns values like instance. That’s why the field isn’t available on insert. Instead of an Insert BR, use an After Update BR with current.instance.changesToNotEmpty() or handle it in an Inbound Email Action to ensure your logic only runs once the field is set.

 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

View solution in original post

4 REPLIES 4

Nehal Dhuri
Mega Sage

Hey @AdriàM ,
have you tried current.getDisplayValue('instance') ?

 
Please hit like and mark my response as correct if that helps

Ankur Bawiskar
Tera Patron
Tera Patron

@AdriàM 

what's your business requirement here?

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

M Iftikhar
Giga Sage

Hi @AdriàM ,

sys_email records go through multiple system updates as inbound processing assigns values like instance. That’s why the field isn’t available on insert. Instead of an Insert BR, use an After Update BR with current.instance.changesToNotEmpty() or handle it in an Inbound Email Action to ensure your logic only runs once the field is set.

 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

TejasSN_LogicX
Tera Contributor

Instead of onInsert, use an after update Business Rule with a condition on instance (so it triggers when ServiceNow assigns the email to a record)