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

Welcome!! I guess you marked correct answer to ankur's post.

go to filter Navigator, type sys_attachment.list and add condition as below : YOu need to paste incident sys_id their

find_real_file.png

 

Thank you,
Abhishek Gardade

Hi , 

 

Looks like only 1 answer can be marked as correct. 

I have marked yours because i got your code 1st. 

Thank you so much.. 

 

I'm new to Snow development and team is giving me simple task to perform and understand. 

So looking forward to your replies on my new task and quries. 

Thank u .

you will see my reply Always!!!

Thank you,
Abhishek Gardade

Hi Naveen,

Attachments are by default stored in sys_attachment table this is out of box functionality

for your requirement have before insert/update business rule on incident table

which does this

sample script below

if(!current.hasAttachments()){

gs.addErrorMessage('Plz add an attachment');

current.setAbortAction(true);

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

It's working fine. 

Thank u