- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 06:59 AM
Hi Everyone,
I have a requirement of making attachment mandatory based on the value(Select-box) in one of the catalog item. So, instead of generic attachment(paper clip icon) I have used attachment variable in catalog item. Please refer below image for the variable
Whenever I upload the attachment and submit the form and the attachment would be named with prefix "ZZ_YY".
So, to avoid this I have used After insert BR and wrote a script like this
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "ZZ_YY" + current.getTableName());
gr.addQuery("table_sys_id", current.sys_id);
gr.query();
if (gr.next()) {
gr.table_name = current.getTableName();
gr.update();
}
})(current, previous);
There will be no issue if I attach/upload a proper file for the first attempt in the variable but incase If I want to update the file in attachment variable using upload option and submit the form.
I am able to see the previously attached file not the latest one in request form.
Can anyone please help on this issue?
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 07:36 AM
use this -> orderByDesc()
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 07:00 AM - edited 02-18-2025 07:08 AM
@Ankur Bawiskar Any help on this issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 07:36 AM
use this -> orderByDesc()
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 08:28 AM
Thank You @Ankur Bawiskar it worked.