Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Make Attachment Mandatory in incident form.

Naveen87
Tera Guru

Hello Guys, 

 

I have a task to perform , 

 

In incident form, attachment must be mandatory on submit. 

If there is no attachment then a error msg ("Plz add an attachment")..

This attachment should be stored in sys_attachment table after submittion. 

Plz help . 

1 ACCEPTED SOLUTION

Hello Naveen 

You need to use  hasAttachments and I guess you are using hasAttachment. You missed s at the last

Later I have modified the code and may be thats why its not woking. Check out the udpated code:

(function executeRule(current, previous /*null when async*/) {

gs.addInfoMessage("Result:"+current.hasAttachments());

if(current.hasAttachments() != true){

gs.addInfoMessage("PLease add an attachment");

current.setAbortAction(true);

}

})(current, previous);

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade

View solution in original post

15 REPLIES 15

Hi Abhishek, 

 

Your code is partially running, adding a screenshot plz look into it and tell me what's wrong. 

 

Here why "result:undefined".

Even when attachemnt is added, It's showing same error msg. 

Hello Naveen 

You need to use  hasAttachments and I guess you are using hasAttachment. You missed s at the last

Later I have modified the code and may be thats why its not woking. Check out the udpated code:

(function executeRule(current, previous /*null when async*/) {

gs.addInfoMessage("Result:"+current.hasAttachments());

if(current.hasAttachments() != true){

gs.addInfoMessage("PLease add an attachment");

current.setAbortAction(true);

}

})(current, previous);

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade

I have tested the code  and its working. Above code will for sure, If not Share you code so I can figure it out the error.

Thank you,
Abhishek Gardade

Your simlpy Awesome. 

Thank u so much.. 

 

Now, how to check in sys_attachemnt whether it's saved for not?