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

Sharjeel,

I just changed the word in the business rule

from: while (gr.next()){

to: if (gr.next()){

Although this has not worked. Did you mean to change this in the web services message instead, rather than business rule?

Thanks

Steve

Steve,

 

No, while(gr.next()) was correct no need to change that. 

if(gr.hasNext()) should wrap the lines which is sending the attachment content via Rest api. See a sample code below.

if(gr.hasNext()) {
  r.setStringParameterNoEscape('AttachmentName', 'Attachment');   
  r.setStringParameterNoEscape('AttachmentContent', encData);
  r.setStringParameterNoEscape('AttachmentDescription', '1');

}

 

hasNext() - Determines if there are any more records in the GlideRecord.
next() - Moves to the next record in the GlideRecord.
 
Please mark this correct & helpful if it answered your question.

Thanks & Regards,
Sharjeel
Regards,
Muhammad

Sharjeel,

I updated the business rule and also added the parameters into the web services message, and then generated auto variables, however the message isn't being send when not attaching a Attachment.

are you sure that encData is without the quotes?

Thanks

Steve

Steve,

Yes encData is variable that should be without Quotes. If without attaching attachment rest call is not being made then without looking into the actual code it would be hard to help. 

The idea is to not execute those functions or lines which are related to Attachment thing. We need to put all those lines under if condition. So that until we have attachment those lines doesn't get triggered 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

Sharjeel,

Thank you, please see attached code that I am using the business rule, substitution variables, content of web message if that helps.

Kind regards

Steve