- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 10:46 AM
I'm trying to find the built-in script for the Delete option on Image fields. When an image is Deleted, the image gets wiped, but the value within the field remains as a SysID. I'm attempting to update the Delete script to set the value to "". Thank you for any direction you can provide!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 06:56 PM
@Jake-K You need to write a business rule on Sys_attachment table which would get triggered on the delete operation and check if the deleted record belongs to your table. In the script field of the business rule you can query the parent record and set the photo filed to empty.
Here is an example of how you can remove sys_id on the photo field on the sys_user table when the photo is removed from the photo field.
The moment a picture is uploaded in the photo field, an entry similar to the following gets created in the sys_attachment table.
Please note that table name sys_user has a ZZ_YY prefix. This prefix informs the sys_user form to not to show image as an attachment whenever the record is opened. For more details please refer to https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0868420
While using the delete button the photo gets deleted from the sys_attachment table. However, the residue sys_id of the attachment remains on the sys_user record. You can remove this by creating a business rule as follows.
Here is the sample script for your reference.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var glideRecord = new GlideRecord('sys_user');
if(glideRecord.get(current.table_sys_id)){
glideRecord.setValue('photo','');
glideRecord.update();
}
})(current, previous);
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 06:56 PM
@Jake-K You need to write a business rule on Sys_attachment table which would get triggered on the delete operation and check if the deleted record belongs to your table. In the script field of the business rule you can query the parent record and set the photo filed to empty.
Here is an example of how you can remove sys_id on the photo field on the sys_user table when the photo is removed from the photo field.
The moment a picture is uploaded in the photo field, an entry similar to the following gets created in the sys_attachment table.
Please note that table name sys_user has a ZZ_YY prefix. This prefix informs the sys_user form to not to show image as an attachment whenever the record is opened. For more details please refer to https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0868420
While using the delete button the photo gets deleted from the sys_attachment table. However, the residue sys_id of the attachment remains on the sys_user record. You can remove this by creating a business rule as follows.
Here is the sample script for your reference.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var glideRecord = new GlideRecord('sys_user');
if(glideRecord.get(current.table_sys_id)){
glideRecord.setValue('photo','');
glideRecord.update();
}
})(current, previous);
Hope this helps.