- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:14 AM
HI,
I have a below requirement.
In catalog form i attached excel file. Once RITM created i need to get attachment data in RITM description.
Using below script i am able to get the information related to file name
var recordId = '62826bf03710200044e0bfc8bcbe5df1';
var attGr = new GlideRecord('sys_attachment');
attGr.addQuery('table_sys_id', recordId);
attGr.query();
if(attGr.next())
{
var filename = attGr.getValue('file_name');
gs.info('filename ' + filename);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 08:16 PM
Hi @Rama26
Yes it's possible. You just need to declare an array and push the data into it like below logic:
var arr=[]; //added here
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream('ec41f6da97d711105de6bf36f053afaa');
parser.parse(attachmentStream);
var headers = parser.getColumnHeaders();
var header1 = headers[0];
gs.info('header1 : ' +header1);
while(parser.next()) {
var row = parser.getRow();
arr.push(row[header1].toString()); //added here
//gs.info('Info Message : '+row[header1]) commented this line
}
gs.info(arr); //added here
Hope it helps..
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:48 AM
Hi @Emp 53
As you said attachment type is Excel then you can use GlideExcelParser API to access the data.
See below links for more reference:
Hope it helps.
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 10:03 AM
Hi Murthy,
Using Below script i am able to get attachment data
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream('ec41f6da97d711105de6bf36f053afaa');
parser.parse(attachmentStream);
var headers = parser.getColumnHeaders();
var header1 = headers[0];
gs.info('header1 : ' +header1);
while(parser.next()) {
var row = parser.getRow();
gs.info('Info Message : '+row[header1])
}
*** Script: header1 : Info
*** Script: Info Message : alejandra.prenatt@example.com
*** Script: Info Message : abraham.lincoln@example.com
*** Script: Info Message : admin@example.com
But is there any way to get the information like "alejandra.prenatt@example.com,abraham.lincoln@example.com,admin@example.com"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 08:16 PM
Hi @Rama26
Yes it's possible. You just need to declare an array and push the data into it like below logic:
var arr=[]; //added here
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream('ec41f6da97d711105de6bf36f053afaa');
parser.parse(attachmentStream);
var headers = parser.getColumnHeaders();
var header1 = headers[0];
gs.info('header1 : ' +header1);
while(parser.next()) {
var row = parser.getRow();
arr.push(row[header1].toString()); //added here
//gs.info('Info Message : '+row[header1]) commented this line
}
gs.info(arr); //added here
Hope it helps..
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:54 AM
Hi, You can use below script to get the attachment data . Use the read_data variable to your ritm short description field.
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', recordID);
attachment.query();
if ( attachment.next() ) {
var attachID = attachment.sys_id;
var attach_data = new GlideSysAttachment();
var by_data = attach_data.getBytes(attachment);
read_data = Packages.java.lang.String(by_data);
setAttachmentData(read_data);
}
function setAttachmentData(read_data){
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('number', YourRITMNumber);
grRITM.query();
if(grRITM.next()){
grRITM.description = read_data;
grRITM.update();
}
}
Suresh.