- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 10:33 PM
Hi Team,
I am submitting a new record to a custom table on the portal, before submit I need to check if there are any attachments added to the form. I am using an onSubmit client script for this but when I try to query the sys_attachment table, I dont get any records. The g_form.getUniqueValue() returns -1.
Thanks,
Kannan
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 11:10 PM
Hi,
the above onSubmit client script did you try setting Isolate Script as false on the client script?
or else you can have before insert BR on your table; query sys_attachment table with the current.table_sys_id as current sys id and if record not found then show message and stop form submission
Note: g_form.getUniqueValue() won't give the record sys_id as sys_id is not generated on new record; it only generates once you submit; so BR can have the current.sys_id
Also in scoped app you cannot do GlideRecord in client script; also you cannot perform synchronous GlideAjax in onSubmit script
BR Script: you can enhance it to determine if specific file name is also attached or not
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var attachmentRec = new GlideRecord('sys_attachment');
attachmentRec.addQuery('table_sys_id', current.sys_id);
attachmentRec.addQuery('table_name', <yourTableName>));
attachmentRec.query();
if(!attachmentRec.next()){
gs.addErrorMessage('Attachment required');
current.setAbortAction(true);
}
})(current, previous);
OR
BR Script;
if(!current.hasAttachments()){
gs.addErrorMessage('Attachment required');
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 10:58 PM
Hi Ankur,
No, this is not a record producer. This is a form on the portal. Also I am in a scoped app, document is not accessible in my client script. I even tried adding the system property "glide.script.block.client.globals" but that didn't help as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 11:10 PM
Hi,
the above onSubmit client script did you try setting Isolate Script as false on the client script?
or else you can have before insert BR on your table; query sys_attachment table with the current.table_sys_id as current sys id and if record not found then show message and stop form submission
Note: g_form.getUniqueValue() won't give the record sys_id as sys_id is not generated on new record; it only generates once you submit; so BR can have the current.sys_id
Also in scoped app you cannot do GlideRecord in client script; also you cannot perform synchronous GlideAjax in onSubmit script
BR Script: you can enhance it to determine if specific file name is also attached or not
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var attachmentRec = new GlideRecord('sys_attachment');
attachmentRec.addQuery('table_sys_id', current.sys_id);
attachmentRec.addQuery('table_name', <yourTableName>));
attachmentRec.query();
if(!attachmentRec.next()){
gs.addErrorMessage('Attachment required');
current.setAbortAction(true);
}
})(current, previous);
OR
BR Script;
if(!current.hasAttachments()){
gs.addErrorMessage('Attachment required');
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 11:56 PM
Hi Ankur,
It seems like there was no other option other than using a business rule.
Thanks,
Kannan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 11:26 PM
Hi,
You can open any record , and get the sys_id from header menu options ( as below )
Or you can do like-
function onLoad() {
var incSysid = g_form.getUniqueValue();
alert(incSysid);
}
And for more info please refer this link
https://www.servicenowelite.com/blog/2014/5/19/finding-the-sysid-of-a-record
Please mark correct or helpful if this works.
Thanks
Swapnil