Create .txt file in sys_attachment from data stored in a table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2013 12:40 PM
Has anyone programatically created a text file attachment from data stored in a field in a ServiceNow table from a business rule?
I am essentially trying to emulate the behavior in the Attachment Note workflow activity. I need to create an attachment, but on a table that doesn't support that activity - so I want to include a Run Script activity with code that will allow me to create an attachment on the record.
I was thinking something like:
var file = new GlideRecord("sys_attachment");
file.file_name = "testname.txt";
file.CONTENTS = VARIABLECONTENT;
var sysID = rdp_file.insert();
But am not sure how to actually funnel the text from my variable into the content for the attachment record.
Any help would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 09:51 AM
Nice - so I'd guess you'd be able to create a custom Excel too using this method (albeit, with a more complicated payload)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 02:06 PM
Cool!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2021 03:40 AM
Hi Jogmen,
Gettring below error, when I use var StringUtil = Packages.com.glide.util.StringUtil;
var encodedPayload = StringUtil.base64Encode(attachmentPayload); lines inside function as well.
Any idea?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2021 06:57 AM
Hello Amutha,
Calls to package are more and more restrained by ServiceNow.
But for this case, there is an alternative, you can use :
var stringUtil = new GlideStringUtil(),
encodedPayload = stringUtil.base64Encode(attachmentPayload);
This should work in current versions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2018 05:44 AM
IS there is a way to attach body from inbound email into an incident as an "attachment", every time an incident is created?