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

Hi @Kishor O ,

 

Thank you for marking my solution as helpful! The community now supports multi-solution acceptance, allowing you to accept multiple answers.

MackI
Kilo Sage

hi @Kishor O 

 

Analysis of the Script:

Hardcoded Values: You're hardcoding the short_description, assignment_group, and other fields. This is generally not recommended. Ideally, these should be configurable, perhaps from system properties or a configuration table.
current.update() vs. current.insert(): You're currently using current.insert(), which is the correct approach for creating a new incident. current.update() is used to modify an existing record.
Lack of Input Validation and Sanitization: The script directly uses values from the email body without any validation or sanitization. This is a significant security risk. Malicious content in the email could be injected into your incident, leading to potential issues like cross-site scripting (XSS) or data corruption.
Error Handling: The script lacks proper error handling. What happens if email.body_text is empty or doesn't contain the expected format? What if the caller lookup fails?
Logging: While you have gs.info(), more detailed logging (especially for debugging and auditing) would be beneficial.
Business Logic directly in Inbound Action: Embedding complex parsing logic directly within the inbound email action makes it harder to maintain and reuse. Consider moving parsing and processing logic to a Script Include.
 
Can you share your project story summery so I can try to develop script in my PDI and give you via Update Set!.Let me know your thoughts.
If you like this opinion and your problem is resolved after reviewing and applying it. Please kindly mark this your best answer‌🌠‌ OR  mark it  Helpful ‌‌ if you think that you get some insight from this content relevant to your problem and help me to contribute more to this community
MackI | ServiceNow Developer | 2 *Mainline Certification | LinkedIn Top IT Operation Voice 2023 | Sydney,Australia