Catalog Variable type ATTACHMENT - Documentation? How to get the link of the attachment in an export
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 06:32 AM
We recently opened a Hi Portal case to get missing variable types added, and ATTACHMENT is one of those. It is useful in some specific situations, where more than one attachment is required in particular. I have a question though on how to export/acquire the URL to those attachments so I can export along with the rest of the variables. Here is what I am trying to do...
Customer fills out a form on the portal, it has a couple attachments that get attached (tax stuff). Once this request gets approved and the TASK creates, we have a business rule that exports all the variables into fields on a custom table, and then we have a scheduled export set that looks for new entries on that table, exports to CSV and pushes out to a mid server location where it gets picked up and imported into SAP. We do NOT have a direct API setup at this time.
This works fine for all the usual variables, but attachments are another thing. How to get the attachments available for SAP ingestion?
Is it possible to pull out the URL to those attachments, and put those URLs into the CSV (attachment 1 URL, Attachment 2 URL), and then some guru on the SAP side can use those URLs to copy the attachments over? I already have the BR used to copy variables (trigger is creation of the task), so I am thinking I should be able to do this somehow.
Is there documentation or can someone articulate what options I might have using the ATTACHMENT variable to get the URL, or do I need to setup a query against the RITM (where the attachments get attached), and get the URL that way? Is there a more clever way to do this?
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 08:24 AM - edited ‎04-03-2025 08:51 AM
Bad form to reply to myself, but if there is no way to export the URL of the variable directly and I have to script a query to sys_attachment... It seems the challenge is to know which attachment is the bank attachment and which is the tax attachment. Let alone if there are more attachments than the two required. Assuming that people can randomly name their attachments, I don't see a good way to know which is "attachment 1" or the bank attachment vs attachment 2 / tax attachment.
Hoping someone is clever and knows a way to do this!
Ok, I figured A way... this attachment variable puts links in the RITM variables section, but the actual value of those variables does not contain the URL, even though its there on the RITM view. However, the NAME of the file is saved in the value of the variable, so I can use that to filter which attachment is which on my script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @jlaps
I don’t know if you got the answer for your question but may you try use this code
(function getAttachmentUrls(ritmSysId) {
var result = {};
// Step 1: get variable values
var varGR = new GlideRecord("sc_item_option_mtom");
varGR.addQuery("request_item", ritmSysId);
varGR.query();
while (varGR.next()) {
var variable = varGR.sc_item_option.item_option_new.name; // variable name
var value = varGR.sc_item_option.value; // this will be the filename for attachment variables
result[variable] = { fileName: value, url: null };
}
// Step 2: match with sys_attachment
var attGR = new GlideRecord("sys_attachment");
attGR.addQuery("table_name", "sc_req_item");
attGR.addQuery("table_sys_id", ritmSysId);
attGR.query();
while (attGR.next()) {
var url = gs.getProperty("glide.servlet.uri") + "sys_attachment.do?sys_id=" + attGR.sys_id;
// find which variable references this file name
for (var varName in result) {
if (result[varName].fileName == attGR.file_name.toString()) {
result[varName].url = url;
}
}
}
return result;
})("<RITM_SYS_ID>");