Adding attachment script in Business Rule

SW7
Giga Guru

Hi Community,

I have a business rule attached that work for updating and creating incident tickets over API to external 3rd party, but I am now trying to add to the business rule the capture and sending of attachments, whenever there is an attachment. 

I successful created a test update and get and post of the attachments from Postman (with help of the document that Muhammad had previously sent through "HackLab") however was unsure of how to fit the script and which bits of script to add from the document

, however I am not sure of the JSON script i should be writing to be able get and send the attachments over externally from the business rule.

Just need to add to the business rule (not take away anything because it works fine for creating / updating of incidents) 

Any help much appreciated

Thanks

Steve

 

1 ACCEPTED SOLUTION

I am glad that you got it working. 

 

Just for your information, In case if you need to hit different endpoints based on Insert or update then you can create a script include reusable utility and from BR you can use

current.insert() & current.update() methods to check the operation and based on that you can call your script include passing in dynamic data. I hope this will help you in the future. 

Have a nice day 🙂 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

View solution in original post

40 REPLIES 40

Good to hear that. Please use try catch for error handling and to make your code more robust. 

 

Thanks & Regards,

Sharjeel 

 

 

Regards,
Muhammad

Sharjeel,

Thank you, that's much appreciated, will do

Kind regards

Steve

Sharjeel,

I am in the process of looking into the external 3rd party logging services requests in to ServiceNow and wondered what your thoughts were?

My initial thoughts were to add a catalog item to the Technical Services Catalog and then use either a work flow or flow designer for the request flow?

Just wondered if you had done this with either or these ways?

Many thanks

Steve

Sharjeel,

Regarding the attachment script that works flawlessly where there is an attachment that you sent over (as attached). This works correctly when there is an attachment and gets sent over the API, if there is no attachment attached it fails to send the ticket details over the API,

Is there an if statement or similar that could be used at the beginning to say if no attachment, then don't run? 

Many thanks

Steve 

Steve,

 

Happy to hear that. Regarding the no attachment thing you can wrap the code where you are sending attachment as part of Rest call with if condition like this. Here "gr" is the GlideRecord("sys_attachment") Object of sys_attachment class. 

if (gr.hasNext()){
  .
  .
  .
  .

}

 

Please mark this helpful if it answered your question.

Thanks & Regards,
Sharjeel

Regards,
Muhammad