- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 03:47 AM
Hi team,
i am trying to assign attachment sys_id in to a string field, in "insert business rule on signature_image" table.
I am getting @@@@@1 , @@@@@2 , logs only, i am getting sys_id of the attachment in @@@@@2 log, but not updating in to that field
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.log('@@@@@ABC ');
var request = new GlideRecord('sc_request');
request.addQuery('sys_id',current.document);
request.query();
if(request.next()){
gs.log('@@@@@1 ABC number '+ request.number);
gs.log('@@@@@2 ABC sys id '+current.getUniqueValue());
var id = attachementid();
if(id == 'NOValue'){
gs.log('@@@@@3'+u_current_attachment_sysid);
request.u_current_attachment_sysid = u_current_attachment_sysid;
request.update();
id = attachementid();
}
if(id != 'NOValue') {
gs.log('@@@@@4'+u_current_attachment_sysid);
request.u_current_attachment_sysid = id;
request.update();
}
}
function attachementid(){
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', current.getUniqueValue());
gs.log('ABC jaifdiadsf');
attachment.query();
gs.log('@@@@@5'+u_current_attachment_sysid);
if(attachment.next()){
gs.log('@@@@@6'+u_current_attachment_sysid);
return attachment.sys_id;
}
else
gs.log('@@@@@7'+u_current_attachment_sysid);
return 'NOValue';
}
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 12:05 AM
Hello Deepthi,
Could you please mark the answer as correct as we will not leave this thread unanswered
Regards,
Chalan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 11:48 PM
are you using this line ??
attachment.query(); //you are missing this line of code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 12:01 AM
ya, it worked now.. by mistake it went to before BR... actually it should be async 🙂
thx for ur support

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 12:05 AM
Hello Deepthi,
Could you please mark the answer as correct as we will not leave this thread unanswered
Regards,
Chalan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 12:21 AM
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2021 01:06 PM
HI everyone,
I have a requirement in which we need to check first check the mandatory attachment in serviceportal, which could be done OOB now. Along with that we need to check whether the attachment is excel or not , and if it is excel we need to count the filled rows in it. Any help will be appreciated. I have the code for checking whether the attachment is an excel or not, but its not working in portal as we are using Dom manipulation there . Below is the working code in the Service-now console and also i have the code which counts the excel rows but not able to achieve in portal.. Below are both the codes.
Excel mandatory working in console but not in portal:
Client script
function onSubmit() {
var cat_id = sysparm_item_guid.value;
var attObj = new GlideRecord('sys_attachment');
attObj.addQuery('table_name', 'sc_cart_item');
attObj.addQuery('table_sys_id', cat_id);
attObj.query();
if (attObj.hasNext()) {
while (attObj.next()) {
var typeMatch = 'ms-excel,spreadsheetml';
var typeStr = attObj.content_type.toString();
var typeChk = (typeStr.indexOf(typeMatch[0]) > -1 || typeStr.indexOf(typeMatch[1]) > -1);
var fName = attObj.file_name.toString();
var regex = /\.xlsx$/g;
var extChk = regex.test(fName);
if(!typeChk || (typeChk && !extChk)) {
alert("You must use an Excel spreadsheet for uploading, please remove the existing file and re-attach");
return false;
}
}
}
}
Counting nunmber of rows
Background script
var count=0;
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file attachment
var attachmentStream = attachment.getContentStream('6e9c7aad1b772850c1534159cc4bcb5d'); //sys_id of record from sys_attachment table
parser.parse(attachmentStream);
//retrieve the column headers
var headers = parser.getColumnHeaders();
gs.print("Apoorva"+headers );
var key = headers[0];
var value = headers[1];
while(parser.next())
{
count++;
var row = parser.getRow();
//print row value for both columns
gs.print(row[value]) ; //Uncomment this to get actual data.
}
gs.print('Number of Rows in excel attached are '+count);