- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
I am trying to transfer employee offer letter in "sn_hr_ef_employee_document".
I am using Data Source file Retrieval Method as Attachment.
In CSV file there are three columns
employeeID,AttachmentName,document type,AttachmentContent(Base64 String) which is near about 800 characters.So there is no truncation issue.
In transform map I am mapping this field with Employee,file,document type.
To create a PDF file in sn_hr_ef_employee_document I am using onAfter Transform script.
Last log in the script throws below error "attachment sys id:Could not find a record in table 'sn_hr_ef_employee_document' with sys_id 'a71643b........"
But when trying to Test Data source then data is correctly load into staging table but when I see Target Record
it throws "Attachment not found" error message.
Record "Sys_id" is getting created at the backend but "sn_hr_ef_employee_document_upload.do" ui page throws "Attachment not found" error msg
Attaching screenshot for reference
#HRSD
#EDM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
I think the issue is due to the attachment being written before the target record is committed in the sn_hr_ef_employee_document table.
The transform map creates the target record, but at onAfter, the record isn’t yet committed to the database.
So, when Attachment.write() runs, the target.sys_id exists in memory, but ServiceNow cannot yet find the record in the table.
Use GlideSysAttachment() instead of Attachment()
Prefer the modern API:
var gsa = new GlideSysAttachment();
gsa.write(target, source.u_attachmentname, "application/pdf", base64bytes);This automatically detects the table and sys_id from the target GlideRecord and reduces lookup errors.
ɪꜰ ᴍʏ ᴀɴꜱᴡᴇʀ ʜᴀꜱ ʜᴇʟᴘᴇᴅ ᴡɪᴛʜ ʏᴏᴜʀ Qᴜᴇꜱᴛɪᴏɴ, ᴘʟᴇᴀꜱᴇ ᴍᴀʀᴋ ᴍʏ ᴀɴꜱᴡᴇʀ ᴀꜱ ᴛʜᴇ ᴀᴄᴄᴇᴘᴛᴇᴅ ꜱᴏʟᴜᴛɪᴏɴ ᴀɴᴅ ɢɪᴠᴇ ᴀ ᴛʜᴜᴍʙꜱ ᴜᴘ.
ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ
ꜱʀᴇᴇʀᴀᴍ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
I think the issue is due to the attachment being written before the target record is committed in the sn_hr_ef_employee_document table.
The transform map creates the target record, but at onAfter, the record isn’t yet committed to the database.
So, when Attachment.write() runs, the target.sys_id exists in memory, but ServiceNow cannot yet find the record in the table.
Use GlideSysAttachment() instead of Attachment()
Prefer the modern API:
var gsa = new GlideSysAttachment();
gsa.write(target, source.u_attachmentname, "application/pdf", base64bytes);This automatically detects the table and sys_id from the target GlideRecord and reduces lookup errors.
ɪꜰ ᴍʏ ᴀɴꜱᴡᴇʀ ʜᴀꜱ ʜᴇʟᴘᴇᴅ ᴡɪᴛʜ ʏᴏᴜʀ Qᴜᴇꜱᴛɪᴏɴ, ᴘʟᴇᴀꜱᴇ ᴍᴀʀᴋ ᴍʏ ᴀɴꜱᴡᴇʀ ᴀꜱ ᴛʜᴇ ᴀᴄᴄᴇᴘᴛᴇᴅ ꜱᴏʟᴜᴛɪᴏɴ ᴀɴᴅ ɢɪᴠᴇ ᴀ ᴛʜᴜᴍʙꜱ ᴜᴘ.
ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ
ꜱʀᴇᴇʀᴀᴍ
