Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Check for attachments?

Edwin Fuller
Tera Guru

On insert or update of the form, if the field "submission_type" is "Client Change Request" I need the user to attach a document before being allowed to submit the form. Any ideas on how I can accomplish this? Examples will be great.

Thanks,

Edwin

1 ACCEPTED SOLUTION

I believe hasAttachmensts() is not allowed in scope applications. Then remove the conditions and use this in the script



var gr= new GlideRecord('sys_attachment');


gr.addQuery('table_sys_id',current.getValue('sys_id'));


gr.query();


if(!gr.hasNext()){


gs.addErrorMessage("No attachments");


current.setAbortAction(true);


}


View solution in original post

6 REPLIES 6

Abhinay Erra
Giga Sage

Write a before business rule.


When: before insert


Conditions: !current.hasAttachments()


Script:


gs.addErrorMessage("No attachments");


current.setAbortAction(true);


I'm receiving the following error:



Function hasAttachments is not allowed in scope x_hemas_connectus2


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




  // Add your code here


if (!current.hasAttachments())


{  


gs.addErrorMessage('There is no attachment');  


current.setAbortAction(true);  


}


})(current, previous);


I believe hasAttachmensts() is not allowed in scope applications. Then remove the conditions and use this in the script



var gr= new GlideRecord('sys_attachment');


gr.addQuery('table_sys_id',current.getValue('sys_id'));


gr.query();


if(!gr.hasNext()){


gs.addErrorMessage("No attachments");


current.setAbortAction(true);


}