Converting attachment to base64 in form or workflow.

rambabu1
Giga Expert

Hi All,

In the form i have a attachment field.

once i added excel in that attachment field that excel stored in attachment table.

how can i convert attachment in base64 format. is it possible to using business rule or workflow.

find_real_file.png

find_real_file.png

 

3 REPLIES 3

Community Alums
Not applicable

This article might help:

https://community.servicenow.com/community?id=community_question&sys_id=de244af1db27f3444819fb243996...

And this one:

https://community.servicenow.com/community?id=community_question&sys_id=bedef2e5db58dbc01dcaf3231f96...

There are ways to encode and decode base64 with a script, so you could do this in a workflow activity or a business rule.

HI Timmo,

i written below script

var attachment = new GlideSysAttachment();

var agr = attachment.getAttachments('ZZ_YYsc_cart_item', '816e5064c311111037a02e5ce0013114');

if (agr.next()) {

gs.info(agr.getValue('file_name'));

  var attachmentContent = attachment.getContentBase64(agr);
  gs.info('Attachment content base64 encoded: ' + attachmentContent);

in log i am getting the file name correct but base64 format getting undefined

*** Script: Bulk.xlsx
*** Script: Attachment content base64 encoded: undefined

Allen Andreas
Administrator
Administrator

Hi,

You can refer to the GlideSysAttachment API, for example: https://developer.servicenow.com/dev.do#!/reference/api/rome/server/no-namespace/c_GlideSysAttachmen...

As far as when to do this, you can do it in business rule or workflow, anywhere you have access to server side script that's relevant to this process. That's something you'll want to decide as far as how and when to do it. Workflow would be more relevant...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!