- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2021 02:52 AM
Hi All,
Wanted your help for my requirement where I have to use Script Include and an OnSubmit client script using GlideAjax.
Requirement is : 1. I have one checkbox in my catalog item so when i check the checkbox without adding the attachment while submitting the form it should give me an alert to add the attachment.
2.Adding to this, the second thing in the same requirement is if i add an attachment but doesn't mark the checkbox as checked so while submitting the form, the checkbox should be default tick.
Please give your suggestions.
Thanks in Advance.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2021 11:26 PM
Hi,
You can simply achieve this by following the below steps:
1) Create a UI Script, by navigating to UI Script module. Advantage with this approach is you don't need to use DOM directly and it will be a s a reusable utility and can be used in any client script with bare minimum effort:
UI Script as below:
function getSCAttachmentCount() {
var length;
try {
length = angular.element("#sc_cat_item").scope().attachments.length;
} catch (e) {
length = -1;
}
return length;
}
Client Script:
Write an On Submit Catalog Client script on your catalog item with below code as written:
function onSubmit() {
//Type appropriate comment here, and begin script below
var count = getSCAttachmentCount(); // Function called from UI Script to valdiate the count of attachments uploaded.
if(g_form.getValue('Pass your Backend Variable Name here') == true){
if (count <= 0) {
alert('You must attach template before submitting this request.');
return false;
}
}
else if(count > 0){
if(g_form.getValue('Pass your Backend Variable Name here') == false){
g_form.addErrorMessage('Please seelct the field as True');
return false;
}
}
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2021 08:08 AM
Hi Abhay,
I tried for the first condition for making an attachment mandatory while submitting if the checkbox is checked by an OnSubmit client script and script include using GlideAjax and i am getting an alert but on the portal after getting an alert the item is moving to cart so can you guide me in that how can i stop it to move into cart after getting an alert.
Thanks,
Isha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2021 08:37 AM
- Basically you have to make return false in on sumbit catalog client script
I will recreate this scenario in my pdi i paste the code soon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2021 09:00 AM
Add this code and change the feild name of you check box and test this in your instance.
function onSubmit() {
//Works in non-portal ui
try {
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('You must attach the completed form before submitting this request.');
return false;
}
else if(g_form.getValue('check_box')=='false') {
g_form.setValue('check_box','true');
}
}
//For Service Portal
catch(e) {
var count = getSCAttachmentCount();
if(count <= 0) {
alert('You must attach the completed form before submitting this request.');
return false;
}
else if(g_form.getValue('check_box')=='false') {
g_form.setValue('check_box','true');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2021 09:27 AM
- Did this worked in your catalog item ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2021 09:47 AM
Hi Abhay,
No it didn't, as its said document.getElementByID() is basically performing DOM Manipulation, which is not supported on the platform so looking for an alternate solution for this.
