GlideRecord query not working??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2018 08:38 AM
hi all,
I've got an onSubmit catalog client script that is meant to prevent the submission of a catalog item if there is no attachment already attached to the form. I'm using a script I've used before, in the other cases it works fine. However in this catalog client script, the script is breaking on the line identified below. The upper part of the script is checking if a certain field is empty, and if it is empty it then checks if there's an attachment...and if there is no attachment it should then throw the "alert()". Anyone see why my var attachment = new GlideRecord('sys_attachment'); line is breaking the script?
thanks!
Here's the full script:
function onSubmit() {
//check first if Entry #1 fields are entered
g_form.addInfoMessage('item_number1 is '+g_form.getValue('item_number1'));
if (g_form.getValue('item_number1') != ''){
return;
}
else {
//check for attachment
g_form.addInfoMessage('item_number1 is empty');
var sys_id = gel('sysparm_item_guid').value;
g_form.addInfoMessage('hello'); //this message is being displayed
var attachment = new GlideRecord('sys_attachment'); //this line appears to breaking the script
g_form.addInfoMessage('hello2');// this message is NOT being displayed
attachment.addQuery('table_name','x_cur_erp_sm_request');
attachment.addQuery('table_sys_id',sys_id);
attachment.query();
if (!attachment.next()) {
alert ("Please attach a completed Service Delivery Request form before submitting this request if not using the available fields on the form.");
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 10:13 AM
Hi Sanjiv,
sorry I got diverted by another priority, shooting to try your script this week...I'll get back with you...thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 05:11 PM
could this be a Jakarta bug?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 05:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 05:32 PM
Hi Sanjiv and Michael,
so in the context of a Before business rule, this proved to be quite easy since we have access to "current". In this capacity I needed to prevent setting the state on a Problem record if there was no attachment, and this script below worked perfectly. Still going to need be able to do the same thing on catalog items in Service Portal, so still working on that. thanks again you guys for your help as always!
(function executeRule(current, previous /*null when async*/) {
// Check for attachment
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_name','problem');
attachment.addQuery('table_sys_id',current.sys_id);
attachment.query();
if (!attachment.next()){
gs.addErrorMessage('Please attach the completed RCA Template before setting the State to Pending Review');
current.setAbortAction(true);
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2018 04:38 PM
This thread has a solution that works in both desktop view and service portal: https://community.servicenow.com/community?id=community_question&sys_id=dd618729db98dbc01dcaf3231f96...