## 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 sys_id. ``` sendnotification(); function sendnotification() { try { var r = new sn_ws.RESTMessageV2('IqtrackTest', 'AttachmentPost'); r.setStringParameterNoEscape('sys_id',current.sys_id); r.setStringParameterNoEscape('sysparm_TableName',current.getTableName()); r.setStringParameterNoEscape('Action',"Attachment_Renamed"); 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.