- 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-11-2017 01:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 02:00 AM
Hi Ks,
Yes you can check onSubmit and stop form submission if more than 1 attachments.
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){
alert("Only 1 attachment can be added");
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-11-2017 03:17 AM
Hi Ankur,
Above shared code, I have already implemented but this is running when the user inserts attachment and click on order now button.
Also, I forgot to mention that I am working on Geneva version.
What I am trying to do, is to stop user to add multiple attachments before submitting the form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 03:37 AM
Hi Ks,
So it will stop the user from form submission if more than 1 attachments. I think you are saying that in scoped app gel() and GlideRecord() in client side won't work.
So one solution to that is have this onSubmit client script in global scope and test it once.
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-11-2017 05:01 AM
Hi Ankur,
Let me rephrase my question. Below is the attachment window which opens when the user tries to insert attachment.
I am working in global scope application. on Submit script works fine but I have a requirement where I want to prompt the user when then click on Attach button highlighted in yellow.
This attachment window looks slightly different in Geneva.