- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2020 09:46 PM
the condition is when a user attaches the attachment in catalog item if the excell headers didnt matched with {number,name,assigned to ,assignment group) the attachment should not attach to the catalog item
by using Glide Ajax in catalog item i trie this
if the attachment headers matched the below condition
if it matches then only the attachment should be created in sc_req_item
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2020 04:39 AM
Hi,
Please find the scripts below
I just tested with 1 excel file containing the name header and other which didn't contain the name header
You can enhance it as per your need
function onSubmit(){
var cat_id = g_form.getValue('sysparm_item_guid');
var ga = new GlideAjax('validateheaders');
ga.addParam('sysparm_name', 'validate');
ga.addParam('sysparm_item_guid', cat_id);
ga.getXMLWait();
var answer = ga.getAnswer();
if(answer == 'false'){
g_form.addErrorMessage('not valid headers');
return false;
}
}
Script Include:
var validateheaders = Class.create();
validateheaders.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validate: function() {
var attachID;
var test = this.getParameter('sysparm_item_guid');
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', test);
gr.addQuery('table_name','ZZ_YYsc_cart_item');
gr.query();
if (gr.next()) {
attachID = gr.getUniqueValue();
}
var stream = new GlideSysAttachment().getContentStream(attachID);
var parser = new sn_impex.GlideExcelParser();
parser.parse(stream);
var headers = parser.getColumnHeaders();
var arr = headers.toString().split(',');
if(arr.indexOf('Name') == -1)
return false;
/*if ((arr.indexOf('Name') == -1) || (arr.indexOf('Number') == -1) || (arr.indexOf('assigned to') == -1) || (arr.indexOf('assignment group') == -1) || (arr.indexOf('short description') == -1)) {
return 'false';
}
*/
return 'true';
},
type: 'validateheaders'
});
Output:
Regards
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
12-28-2020 11:38 PM
OnChange will not work on file upload.
write onBefore BR insert on sys_attachment table
Table name is sc_req_item
then in script, you do the check and add
gs.addErrorMessage("Kindly check the headers");
current.setAbortAction(true)
Mark the comment as a correct answer and helpful if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2020 11:47 PM