Skip to content
← Back to activity

Immutable solution version

ServiceNow renaming attachment not getting SysId

Version 2Sign in to save

Complete solution

ServiceNow renaming attachment not getting SysId. try this ``` var record = new GlideRecord('sys_attachment'); record.addQuery('user_name',gs.getUserName()); record.orderByDesc('sys_updated_on'); record.setLimit(1); record.query(); if (record.next()) { gs.print(record.getValue("sys_id")); gs.print(record.getDisplayValue("file_name")); gs.error("file name"+record.getDisplayValue("file_name")); } ``` Use when hitting this exact issue. Not for unrelated errors or different features.

TL;DR

Try this `` var record = new GlideRecord('sys_attachment'); record.addQuery('user_name',gs.getUserName()); record.orderByDesc('sys_updated_on'); record.setLimit(1); record.query(); if (record.next()) { gs.print(record.getValue("sys_id")); gs.print(record.getDisplayValue("file_name")); gs.error("file name"+record.getDisplayValue("file_name")); }

Fix

  1. Try this `` var record = new GlideRecord('sys_attachment'); record.addQuery('user_name',gs.getUserName()); record.orderByDesc('sys_updated_on'); record.setLimit(1); record.query(); if (record.next()) { gs.print(record.getValue("sys_id")); gs.print(record.getDisplayValue("file_name")); gs.error("file name"+record.getDisplayValue("file_name")); } `` Expected: you can confirm this matches your situation.

When to use

  • You are dealing with this situation.
  • The symptom matches: ServiceNow renaming attachment not getting SysId.

When NOT to use

  • Unrelated issues with a different cause.
  • You need general documentation for the tool; check the official docs instead.

Compatibility

Reported per the linked source.

Variant phrasings

ServiceNow renaming attachment not getting SysId

Why it happens

Stack Overflow question (score 3, has accepted answer): In ServiceNow, I have written script in business login - script actions. While adding and deleting I am getting sysId but when renaming the attachment I am not able to get sysid. ``` sendnotification(); function sendnotification() { try { var r = new snws.RESTMessageV2('IqtrackTest', 'AttachmentPost'); r.setStringParameterNoEscape('sysid',current.sysid); r.setStringParameterNoEscape('sysparmTableName',current.getTableName()); r.setStringParameterNoEscape('Action',"AttachmentRenamed"); var response = r.execute(); var responseBody = response.getBody(); var httpStatus = response.getStatusCode(); } catch(ex) { var message = ex.getMessage(); } } ```

Edge cases

  • If your error message differs even slightly, this is probably a different issue; search the exact text.
  • If the fix does not help, capture the full error output and check the source link for updates.

Evidence

Stack Overflow question (score 3, has accepted answer): In ServiceNow, I have written script in business login - script actions. While adding and deleting I am getting sysId but when renaming the attachment I am not able to get sysid. ``` sendnotification(); function sendnotification() { try { var r = new snws.RESTMessageV2('IqtrackTest', 'AttachmentPost'); r.setStringParameterNoEscape('sysid',current.sysid); r.setStringParameterNoEscape('sysparmTableName',current.getTableName()); r.setStringParameterNoEscape('Action',"AttachmentRenamed"); var response = r.execute(); var responseBody = response.getBody(); var httpStatus = response.getStatusCode(); } catch(ex) { var message = ex.getMessage(); } } `` Resolved: try this var record = new GlideRecord('sys_attachment'); record.addQuery('user_name',gs.getUserName()); record.orderByDesc('sys_updated_on'); record.setLimit(1); record.query(); if (record.next()) { gs.print(record.getValue("sys_id")); gs.print(record.getDisplayValue("file_name")); gs.error("file name"+record.getDisplayValue("file_name")); } `` Source: https://stackoverflow.com/questions/44498845/servicenow-renaming-attachment-not-getting-sysid

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_E1nQKfwi52GMIW2mvmw4IA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ServiceNow renaming attachment not getting SysId <span>— Vectle</span></a>