- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 11:37 PM
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 .
Solved! Go to Solution.
- Labels:
-
Field Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2019 12:15 AM
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
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 11:42 PM
Hi,
You can make attachment mandatory by using business rule.
There is one GlideSystem method to check Attachment and it returns true or false.
You can use this method.
"gs.hasAttachment ()"
and if false you can set Abort action true.
Regards,
Sushant Kadam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 11:52 PM
Hello Naveen,
Check out my article on for your requirement.
Possible Ways for Making an Attachment Mandatory
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 11:58 PM
Hi,
try this code
function onSubmit() {
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", "incident");
att.addQuery("sys_created_by", g_user.userName);
att.addQuery("sys_created_on", '>=', 'javascript:gs.minutesAgo(10)');
att.query();
if (!att.next()) {
alert("Please attach the requested form before submitting.");
return false;
}
return true;
}
else
You can either do this in the client script or via a business rule. With a business rule you can have it fire on a certain state change or condition and query for the attachment. So create a before, advanced business rule and the following example script should work for you:
var attachRec = new GlideRecord("sys_attachment");
attachRec.addQuery("table_name", current.getTableName());
attachRec.addQuery("table_sys_id", current.sys_id);
attachRec.query();
if (!attachRec.next()) {
gs.addErrorMessage("You must attach a complete import template before submitting.");
current.setAbortAction(true);
}
If my reply helps you at all, I’d really appreciate it if you click the Helpful button and if my reply is the answer you were looking for, it would be awesome if you could click both the Helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 11:59 PM
Hello Naveen,
Simply create a BEFORE UPDATE/INSERT Business rule and add following 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);
Also Check out this article as well.
Possible Ways for Making an Attachment Mandatory : Service Portal/Native UI
References:
https://developer.servicenow.com/app.do#!/api_doc?v=london&id=r_GlideRecord-hasAttachments
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies
Abhishek Gardade