How to place the attachment links in record producer table's description field?

Rajini2
Mega Sage

When the record producer is submitted, I need the attachment links to show up in my description field.

Here is the code. It works when I hardcode the sysid and test it in background script. But does not work within the record producer. Any suggestions?

var attachmentLinks = "";
var grAttach = new GlideRecord('sys_attachment');
grAttach.addQuery('table_sys_id', current.getUniqueValue());
grAttach.addQuery('table_name', current.getTableName());
grAttach.query();
while (grAttach.next()) {
	gs.log("grAttach.sys_id-------------" + grAttach.sys_id);
	attachmentLinks += gs.getProperty('glide.servlet.uri') + "sys_attachment.do?sys_id=" + grAttach.sys_id +"\n";
}
current.description = attachmentLinks;

 

9 REPLIES 9

Brad Bowman
Kilo Patron
Kilo Patron

I assume you are running this in the Script field on the Record Producer definition, not an onSubmit Catalog Client Script,...  I had thought this would be a timing issue - the script doesn't know the sys_id of the record that's about to be created, but I was able to populate description with current.getUniqueValue() and current.getTableName(), and those values match the attachment table record - it's not using a sc_cart placeholder until after the RP is submitted.  Are you seeing the log?  If you add more at the beginning of the script and before the while do you see those?

Yes this script is in the Record producer script section. I see the logs for current.sys_id, current.getTableName(), current.getUniqueValue(), but not going inside the while loop. 

 

Yes I added logs beginning of the script and just above the while, I am seeing the log values. I don't know what is preventing it to go inside the loop.

 

var attachmentLinks = "";
gs.log("current.sys_id-------------" + current.sys_id);
var grAttach = new GlideRecord('sys_attachment');
grAttach.addQuery('table_sys_id', current.getUniqueValue());
grAttach.addQuery('table_name', current.getTableName());
grAttach.query();
gs.log("Table name: " + current.getTableName() + ", Sys ID: "+current.getUniqueValue());
while (grAttach.next()) {
	gs.log("grAttach.sys_id-------------" + grAttach.sys_id);
	attachmentLinks += gs.getProperty('glide.servlet.uri') + "sys_attachment.do?sys_id=" + grAttach.sys_id +"\n";
}

 

Are you attaching a file in the Record Producer via the paper clip icon, or an attachment type variable?  Are you doing this in the native UI or Service Portal / ESC / ...?

Attaching with the paper clip icon, in the service portal.