Can we use Packages.java.lang.String(bytesInFile) in business rule?

saranyavs
Tera Expert

Hi Team,

I want to know the alternative method for using the below java package in business rule. I have used this package to fetch data from an attachment for live chat requirement.

find_real_file.png

1 ACCEPTED SOLUTION

Hi,

So basically you want to get the content of the file.

For scoped application you can use this

var attachment = new GlideSysAttachment();
var incidentSysID = '0e352ec80745ac54540bf2508c1ed0b7';

var agr = attachment.getAttachments('sc_cart_item', incidentSysID);

if (agr.next()) {
  var attachmentContent = attachment.getContent(agr);
  gs.info('Attachment content: ' + attachmentContent);
}

For global application you can use this

var sysIdOfRecord = '0e352ec80745ac54540bf2508c1ed0b7';

var grAttachment = new GlideRecord('sys_attachment');

grAttachment.get('table_sys_id', sysIdOfRecord);

var ga = new GlideSysAttachment();

var base64EncodedData = GlideBase64.encode(ga.getBytes(grAttachment));

var data = GlideStringUtil.base64Decode(base64EncodedData);

gs.print("Information Available in File: " + data);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Glad to help.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

How can we loop through each line from the variable?

In this case 'data' variable having data, can we go through line by line?

If we can loop through then I wanted to add each line value to an array and the array will be used in next step of flow to update a record.

Thanks