- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2022 10:16 AM
I need to make attachment is mandatory based on condition. There is a check box in the form If I select that one then it should become attachment mandatory how to implement that please help me out.
I have used below Script but it is become mandatory for entire form I want it for particular variable only
Please check attachment
function onSubmit() {
var cat_id = g_form.getValue('sysparm_item_guid');
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
alert("Attachment is mandatory if you select Preapproved");
return false;
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2022 10:51 AM
Hi,
I would suggest to use the attachment type variable for attaching the attachment and us UI policy to make it mandatory based on your required conditions.
You can achieve it with out scripting and It is recomanded as a best practices.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 12:06 AM
Write an on submit Catalog Client script and put the backend value of your checkbox variable in place of "YOUR_Check_box".
function onSubmit() {
//Type appropriate comment here, and begin script below
var catalogItemID = g_form.getValue('sysparm_item_guid');
var test = g_form.getValue('YOUR_Check_box');
if (test == 'true') {
var count = getSCAttachmentCount();
if (count <= 0) {
getMessage('mandatory_attachment', function(msg) {
g_form.addErrorMessage(msg);
});
return false;
}
} else {
return true;
}
}
Mark ✅ Correct if this solves your issue and also mark ???? Helpful if you find my response worthy based on the impact.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2023 12:42 AM
Getting error in console getSCAttachmentCount is not defined.