- 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 05:06 AM
Hi Ks,
That would require following 2 ways:
1) try to modify out of the box attachment ui page and add code when user hits Attach button
2) have a copy of attachment ui page and try modifying the code
the first option would be a global impact since that is the out of box attachment ui page
the second option may or may not be a success, it depends on trial and error and understanding of complete jelly script of existing attachment ui page.
I would recommend to avoid both the options and have script onSubmit and tell the client/customer that it is out of box functionality and even if achieved may break in future upgrades and ServiceNow won't support on that since you modified the code.
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-12-2017 12:48 AM
Hi Ankur,
Thanks for detailed explanation. I tried using another approach for above feature.
I have created a UI page for attachment where I am using input type file, that way it allows users to select only one attachment.
However, I am not very sure how should I proceed further after selection of attachment. What I understand is selected attachment should be inserted in the attachment. Can you please guide me further on this
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_form>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td><input type="file" name="fileupload" value="fileupload" id="fileupload"></input></td>
<td nowrap="true"><input type="submit" value="Add Invoice"></input></td></tr>
</table>
</g:ui_form>
</j:jelly>
Thanks in Advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 01:05 AM
Hi Ks,
Why to have custom ui page for this and not use out of box attachment functionality? Any specific reason for this
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-12-2017 02:14 AM
The client doesn't want to use out of the box functionality.The requirement is to have this attachment option on catalog item as per user defined order.