- 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
12-31-2019 06:45 AM
is this in Service Portal or native UI?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2019 06:50 AM
Service Portal I have used a catalog client script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2019 06:50 AM
try now.
function onSubmit() {
var myFieldValue = g_form.getValue('polygon_details_attached');
//Check if meant to have an attachment
if (myFieldValue == "Yes") {
var cat_id = g_form.getUniqueValue();
var gr = new GlideRecord("sys_attachment");
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;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2019 06:56 AM
no 😞 count is still showing as 0 when i attach a file