- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2020 09:11 PM
This code is giving the alert of if condition and stopping the submission even i am attaching a file.
whats wrong in my code?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2020 11:24 PM
Hi,
It is not recommended to use GlideRecord in client scripts still if you want to achieve by client scripts then you can try with below code.
function onSubmit() {
//Type appropriate comment here, and begin script below
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("You must add an attachment before submitting this request.");
return false;
}
}
Thanks,
Pooja M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2020 11:46 PM
Thank you so much !its working fine.
please explain me what is the parameter sysparm_item_guid it is a field or how can i use it for further codings
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2020 01:24 AM
Hi,
If you want to know the parameter you can go through below link.
https://hi.service-now.com/kb_view.do?sysparm_article=KB0723775
Thanks,
Pooja M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2020 09:28 AM
Hi Uma,
Did you get chance to go through the above link provided by me.
And if my answer helped you to solve your query please mark it as correct and close the thread.
Thanks,
Pooja M

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2020 08:00 AM
Hi Uma
I would like to add my view to this Thread
gel is just a shortcut for " document.getElementById ", it's javascript function.
mostly used in client side scripting.
gel('sysparm_item_guid').value : current cart item in the order guide.
Usage of sysparm_item_guid in the client scripts for getting the sys_id of the current catalog item works perfectly fine in Platform UI.
However, the same script fails to retrieve sys_id in service portal.
instead of using the syssparm_item_guid we use g_form.getUniqueValue(); to fetch the sys_id in service portal.
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2020 09:39 AM
Hi Uma,
For making attachement mandatory in portal you can use directly the mandatory attachment field on the catalog item and it will work and for native you can use this script.
Write an onsubmit client script which will run only on desktop and in this we are using DOM manipulation.
function onSubmit() {
//Type appropriate comment here, and begin script below
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
alert('Please make sure you have attached the completed template before submitting this request');
return false;
}
else{
alert('thankyou for submitting');
return true;
}
}
In this script we are using DOM so you need to make the isolated script to false. This field is not present in the form you have to bring the field to the form OR you can do it via list layout. (As highlighted)
By default it is true and you have to make it false.
Mark helpful and correct if it helps.
Thanks,
CB