- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 10:46 PM
Hi Team,
I am struggling to make the OOTB attachment icon mandatory based on variable value. I have tried almost everything available here but nothing is working for me. Right now my current onSubmit() script looks like below:
function onSubmit() {
var status = g_form.getValue('trainings_completed');
if (status == 'Yes') {
var cart_id = g_form.getValue('sysparm_item_guid');
alert("cart ID is " + cart_id);
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cart_id);
gr.query();
if (!gr.next()) {
alert("You must add an attachment before submitting this request.");
return false;
}
}
}
cart_id is showing empty during execution
unfortunately this is not working. Please help me to get this work or suggest any other alternate way to achieve this.
Thanks
Bishal
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 11:19 PM - edited 01-28-2025 11:21 PM
Hi @bishalsharm
Is the BR in Global scope?
Try below code
(function executeRule(current, previous /*null when async*/) {
var con = new GlideRecord('u_contract');
con.addEncodedQuery('u_parent_ritm='+current.getUniqueValue());
con.query();
if(con.next())
{
var attach = new GlideSysAttachment();
var result = attach.copy('sc_req_item', current.getUniqueValue(),'u_contract', contract.sys_id);
}
})(current, previous);
Check the syntax of GlideSysattachment copy - GlideSysAttachment - copy
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 11:11 PM - edited 01-28-2025 11:13 PM
Hi @bishalsharm
GlideRecord should not be used in client side scripting. It is server side API and if you want server side info then use GlideAjax.
In this Particular scenario, You don't need Glide Ajax too you can try the solution from links provided by Viraj.
Similar use case- https://www.servicenow.com/community/developer-blog/verify-mandatory-attachments-count-on-catalog-it...
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 11:17 PM
Hi @Voona Rohila,
Option 2 from below community post worked for me
but can u take a look on the additional query i posted here. any idea ?
Thanks
Bishal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 11:19 PM - edited 01-28-2025 11:21 PM
Hi @bishalsharm
Is the BR in Global scope?
Try below code
(function executeRule(current, previous /*null when async*/) {
var con = new GlideRecord('u_contract');
con.addEncodedQuery('u_parent_ritm='+current.getUniqueValue());
con.query();
if(con.next())
{
var attach = new GlideSysAttachment();
var result = attach.copy('sc_req_item', current.getUniqueValue(),'u_contract', contract.sys_id);
}
})(current, previous);
Check the syntax of GlideSysattachment copy - GlideSysAttachment - copy
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 11:29 PM
Hi @Voona Rohila ,
This code is working thank you so much for your dedicated response 🙂
Thanks
Bishal