- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2019 06:43 AM
Hi I have used a number of suggestions I found online to check if an attachment is attached but most just error. The closest i get is below I check first if a selection is yes then if it is I run the code below:
This gives me alert 2 msg then alert 3 msg with a value of 0 if attached or not,
Any help would be very much appreciated, thank you 🙂
function onSubmit() {
var myFieldValue = g_form.getValue('polygon_details_attached');
//Check if meant to have an attachment
if (myFieldValue == "Yes") {
var cat_id = 'sysparm_item_guid'.value;
var gr = new GlideRecord("sys_attachment");
alert ("its yes 2");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
alert("its yes3 = " + gr.getRowCount());
if (!gr.next()) {
alert("You must attach a file to submit.");
return false;
}
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2020 02:25 AM
This may help:
Possible Ways for Making an Attachment Mandatory : Service Portal/Native UI
Please mark as Correct Answer and Helpful.
Thank You!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2020 02:13 AM
Hi the attachment is only under 1 circumstance, so this option will not work for me, I did try it but it asked for it for every request, and I only want if they select a specific option
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2020 02:25 AM
This may help:
Possible Ways for Making an Attachment Mandatory : Service Portal/Native UI
Please mark as Correct Answer and Helpful.
Thank You!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2020 03:09 AM
this worked
function onSubmit() {
var myFieldValue = g_form.getValue('polygon_details_attached');
//Check if meant to have an attachment
if (myFieldValue == "Yes") {
if(this.document.getElementsByClassName('get-attachment').length == 0) {
alert('You must add an attachment before submitting this request.');
return false;
}
}
}
with the isolate script not ticked thank you