Inbound email action script

Kishor O
Tera Sage

Should we need to use current.update() or current.insert in inbound email action script for creating new incident.

I am using the script below. Is this correct, or should I make any modifications to comply with best practices?

KishorO_0-1736772392100.png

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Kishor O 

best to check OOB inbound action on incident table

you should use current.insert() to insert a new record

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

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Kishor O 

best to check OOB inbound action on incident table

you should use current.insert() to insert a new record

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
Tera Patron
Tera Patron

@Kishor O 

current.update() will be used if you are using the email type as Reply and some user replies to email which he/she has received from instance

This will update the record associated with that inbound email

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

Francis Cavaciu
Giga Guru

As suggested by @Ankur Bawiskar , I would use the OOTB examples as a guide. Note the OOTB also wraps the insert with some additional validation that the user should be able to create the Incident

if(current.canCreate())
current.insert();

.

FrancisCavaciu_0-1736773370703.png

 

Runjay Patel
Giga Sage

Hi @Kishor O ,

 

In the case of creating a new Incident , you should be using current.insert() to create the new record. If the script is trying to update an existing Incident, then you would use current.update().

 

also add the below validator 

 

if (current.canWrite())
		current.update();


if(current.canCreate())
current.insert();

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------