- 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 07:39 PM
- Hello isha there is feild called isolate script in client script form make that to false then it will run
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-14-2021 09:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-14-2021 11:12 PM
Hi Isha
try the below onsubmit() script it works fine for me
function onSubmit() {
var a = g_form.getValue('checkbox'); // Map your field name
if (a == 'true') {
if (this.document.getElementsByClassName('get-attachment').length < 1) {
alert('attachment_is_mandatory');
return false;
}
}
if (a == 'false') {
if ((this.document.getElementsByClassName('get-attachment').length > 0) && (a == 'false')) {
g_form.setValue('checkbox', true); // Map your field name
}
}
}
=(tested)
Let me know if any
Regards,
Rakesh
- 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-15-2021 11:31 PM
Hi,
If your query is resolved, can you please mark my answer as correct and close this thread.
Regards,
Shloke
Regards,
Shloke