- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 02:32 AM
Hi All,
I have created a macro for adding attachments on catalog item( Client don't want to use oob feature) and now wanted to restrict the user from adding more than one attachment. Also, wanted to add an override feature.
So, If there is more than one attachment, the user should receive a message saying " Only one invoice allowed, do you want to replace the existing one? — Yes/NO"
If the user clicks on "Yes" it should override with the new attachment.
Any help would be appreciated.
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 04:21 AM
Hi Ks,
you can have onSubmit catalog client script to achieve this:
if user clicks on Yes then do you want to remove the latest attachment from the cart ? can you explain more on this
var sys_id = gel('sysparm_item_guid').value; | |
var attachment = new GlideRecord('sys_attachment'); |
attachment.addQuery('table_name','sc_cart_item');
attachment.addQuery('table_sys_id',sys_id); |
attachment.query();
var numberOfAttachments = attachment.rows.length;
if(numberOfAttachments >1){
var confirmBox = confirm("Only one invoice allowed, do you want to replace the existing one? — Yes/NO");
if(confirmBox.toString() == 'true'){
// logic to remove latest attachment
return true;
}
else{
return false;
}
}
return true;
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 04:21 AM
Hi Ks,
you can have onSubmit catalog client script to achieve this:
if user clicks on Yes then do you want to remove the latest attachment from the cart ? can you explain more on this
var sys_id = gel('sysparm_item_guid').value; | |
var attachment = new GlideRecord('sys_attachment'); |
attachment.addQuery('table_name','sc_cart_item');
attachment.addQuery('table_sys_id',sys_id); |
attachment.query();
var numberOfAttachments = attachment.rows.length;
if(numberOfAttachments >1){
var confirmBox = confirm("Only one invoice allowed, do you want to replace the existing one? — Yes/NO");
if(confirmBox.toString() == 'true'){
// logic to remove latest attachment
return true;
}
else{
return false;
}
}
return true;
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 11:36 AM
Hi Ankur,
Thanks for the reply.
Answer to your question -- if the user clicks on Yes then do you want to remove the latest attachment from the cart.
If the user clicks on Yes, I wanted to delete existing attachment and allow them to attach the new attachment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 11:08 PM
Hi Ks,
So consider user attaches 2 attachments file and file and gets the confirm box message. and user clicks on yes then which attachment should be removed?
file 1 or file 2 or the one which was attached recently or both?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2017 04:30 AM
Hi Ks,
Any update on this?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader