- 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 09:57 PM
Hi,
So you are searching for all the headers
you can get all the headers like this using sample script
var gr = new GlideRecord('sys_attachment');
gr.addQuery('sys_id', '62ce7a65070d1c90540bf2508c1ed0c7');
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();
gs.info('Columns are'+headers);
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 10:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2020 11:10 PM
When i make an attachment in catalog item if the excel headers contains these fields mentioned above the attachment should attach in the attachment field if it didnt match then we should get an alert as (please check the excel headers you attached)
I think i should write a onchange client script and use glideajax
Can You help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2020 12:15 AM
Hi,
for this you would require onSubmit Client Script with GlideAjax
You can use synchronous approach shared in this link
How to achieve getXMLWait() functionality on Service Portal
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader