- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 09:31 AM
Hello experts,
How do I have a mandatory check for attachment via ui action? I want the user to submit an attachment before clicking 'submit'. If no 'attachment' then, alert user to add an attachment.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 11:23 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 09:35 AM
Here is an example onSubmit client script I have used to verify attachment:
function onSubmit() {
var rec_id = gel('sysparm_item_guid').value;
var attachRec = new GlideRecord("sys_attachment");
attachRec.addQuery("table_name", "TABLE-NAME-HERE");
attachRec.addQuery("table_sys_id", rec_id);
attachRec.query();
if (!attachRec.next()) {
alert("You must attach a complete import template before submitting.");
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 11:17 AM
thanks for the reply ..
Is this possible to do via UI Action and not Client Script? I was hoping the functionality can be contained within the UI Action button, so it can be used at a different state, rather than onSubmit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 11:23 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 11:41 AM
I tried doing a business rule, it does not seem to work correctly. I did 'before' when 'state' is 'draft' - nothing happened.