Mandatory Attachment on Submit based on Catalog Item Variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2019 03:14 PM
Hello all,
I have a requirement to make an attachment mandatory on submit based on a catalog item variable.
The question is: Are you requesting to relocate more than one phone? (relocate_phone)
If yes: attachment is required
If no: attachment is not required
In the past when making an attachment mandatory in a catalog task I have used business rules or catalog client scripts but in this case I cannot figure it out.
Can anyone assist?
Thanks,
Grace
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2019 01:51 PM
Hi The following codes worked for me:
For Desktop:
function onSubmit() {
var condition= g_form.getValue('condition');
try{
if(condition=='upload_file'){
//Condition to make attachement mandatory is true
var cat_id = g_form.getParameter("sysparm_item_guid");//This will return the sc_cart_item sys_id that is reserved.
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item"); //unnecessary, but improves query efficiency
gr.addQuery("table_sys_id", cat_id);
gr.query(); //synchronous for non-service portal CMS.
if (!gr.hasNext()) {
g_form.addErrorMessage("Please Attach a File");
return false;
}
}
}catch(e){
g_form.addErrorMessage(e);
return false;
}
}
For Mobile/Service Portal:
function onSubmit() {
//Type appropriate comment here, and begin script below
var condition= g_form.getValue('condition');
if(condition=='upload_file')
{
if (this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage('Please Attach a file');return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2020 09:34 PM
Thanks German Monsalve. This worked perfectly for me.
Regards,
Sailesh J
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 10:17 PM
Thank you. This worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2022 05:58 AM
What if their are multiple options which require attachments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2020 11:26 PM
Hey gnunez,
refer below links might help you,
Make Attachment Mandatory - For A particular Catalog Item
Can you make an attachment mandatory?
Attachment mandatory for catalog item
Kindly mark Correct and Helpful if applicable.
Regards,
Indrajit.