- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2017 05:00 AM
Hello All,
I have a requirement to show and force attachment for certain request types. When the request type is change to options which do not enforce
an attachment, how can I remove the already uploaded attachment from the catalog item view?
I have tried to put a catalog client script on Change of Request Type and perform a delete if an attachment record matches, but both deleteRecord and deleteMultiple does nott work. Any help is appreciated.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2017 06:29 AM
If you want to trigger it from a client script, then yes, you can use a GlideAjax query to trigger a server side script include. If you delete from a client script, the form won't be automatically refreshed to recognize the attachment has been deleted.
If you want it to happen when the record is saved, you can use a business rule. It's up to you.
Docs: Client Scripts
Docs: GlideForm
Docs: GlideAjax
Client Script Best Practices - ServiceNow Wiki
Business Rules - ServiceNow Wiki
Business Rules Best Practices - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2017 05:03 AM
The attachment lives in the sys_attachment table. You cannot remove this from the client script. It must be done from the server side with a GlideRecord query.
Example:
var att = new GlideRecord('sys_attachment');
att.addQuery('table_name', 'sc_req_item');
att.addQuery('table_sys_id', 'SYS_ID_OF_THE_RITM');
att.query();
att.deleteMultiple();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2017 06:23 AM
Hi Chuck,
Thank you.
Can you suggest some ideas on how to achieve this? Since not all items have similar requirements, I would really want to delete only those which do not match Request Type + Attachment required combination. Should I use a Script include and pass the current item whenever there is a request type changed and attachment not required?
Also, will this also clear/refresh the current view of the catalog item?
Thanks,
T

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2017 06:29 AM
If you want to trigger it from a client script, then yes, you can use a GlideAjax query to trigger a server side script include. If you delete from a client script, the form won't be automatically refreshed to recognize the attachment has been deleted.
If you want it to happen when the record is saved, you can use a business rule. It's up to you.
Docs: Client Scripts
Docs: GlideForm
Docs: GlideAjax
Client Script Best Practices - ServiceNow Wiki
Business Rules - ServiceNow Wiki
Business Rules Best Practices - ServiceNow Wiki