- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2023 01:33 AM
Hello,
I think I have the code, and I know that I use a field in a different Client script, so I want to understand why my script is not working.
The purpose is to stop the submission when my field is displayed or visible. But the conditions of the visibility of that field if managed with an other script.
So in my script here is how I get my variable and set the code:
function onSubmit() {
//Choices variables concerned
var application_alert = g_form.setDisplay(alert_application, 'true');
// Option PRODUCTION is selected and at least one of the conditions is true
if( application_alert){}
//here's the code to condition the Attachment mandatory
}
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2023 03:05 AM
Thanks to you @Anand Kumar P ,
It did not work but it helped me a lot to find out the solution: the way you declared the variable and set the if, I used it and add an other script like this :
function onSubmit() {
var alertApplicationVisible = g_form.isVisible('alert_application');
if (alertApplicationVisible) {
// Back office
if (location.pathname.indexOf(".do") > -1) {
var demo = new GlideAjax('CheckAttachmentGessyquaForm');
var catalogItemID = g_form.getValue('sysparm_item_guid');
demo.addParam('sysparm_name', 'checkAttachment');
demo.addParam('sysparm_catalog_id', catalogItemID);
demo.getXMLWait();
var attachment=demo.getAnswer();
if(attachments == 'yes'){
return false; // true
} else if(attachment == 'no'){
alert('Please attach a file when the access require is specific');
return false;
}
}
// Service Portal
else {
var count = getSCAttachmentCount();
if(count <= 0) {
alert('Please attach a file when the access require is specific');
return false;
}
}
}
else {
return true;
}
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2023 03:06 AM
Here the solution :
function onSubmit() {
var alertApplicationVisible = g_form.isVisible('alert_application');
if (alertApplicationVisible) {
// Back office
if (location.pathname.indexOf(".do") > -1) {
var demo = new GlideAjax('CheckAttachmentGessyquaForm');
var catalogItemID = g_form.getValue('sysparm_item_guid');
demo.addParam('sysparm_name', 'checkAttachment');
demo.addParam('sysparm_catalog_id', catalogItemID);
demo.getXMLWait();
var attachment=demo.getAnswer();
if(attachments == 'yes'){
return false; // true
} else if(attachment == 'no'){
alert('Please attach a file when the access require is specific');
return false;
}
}
// Service Portal
else {
var count = getSCAttachmentCount();
if(count <= 0) {
alert('Please attach a file when the access require is specific');
return false;
}
}
}
else {
return true;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2023 09:29 AM
Hi @Jeff W NZAO B ,
function onSubmit() {
var alertApplicationVisible = g_form.isVisible('alert_application');
if (alertApplicationVisible) {
g_form.setMandatory('attachment_field', true);
}
}
Please mark it as solution proposed and helpful if it works for you.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2023 03:05 AM
Thanks to you @Anand Kumar P ,
It did not work but it helped me a lot to find out the solution: the way you declared the variable and set the if, I used it and add an other script like this :
function onSubmit() {
var alertApplicationVisible = g_form.isVisible('alert_application');
if (alertApplicationVisible) {
// Back office
if (location.pathname.indexOf(".do") > -1) {
var demo = new GlideAjax('CheckAttachmentGessyquaForm');
var catalogItemID = g_form.getValue('sysparm_item_guid');
demo.addParam('sysparm_name', 'checkAttachment');
demo.addParam('sysparm_catalog_id', catalogItemID);
demo.getXMLWait();
var attachment=demo.getAnswer();
if(attachments == 'yes'){
return false; // true
} else if(attachment == 'no'){
alert('Please attach a file when the access require is specific');
return false;
}
}
// Service Portal
else {
var count = getSCAttachmentCount();
if(count <= 0) {
alert('Please attach a file when the access require is specific');
return false;
}
}
}
else {
return true;
}
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2023 03:06 AM
Here the solution :
function onSubmit() {
var alertApplicationVisible = g_form.isVisible('alert_application');
if (alertApplicationVisible) {
// Back office
if (location.pathname.indexOf(".do") > -1) {
var demo = new GlideAjax('CheckAttachmentGessyquaForm');
var catalogItemID = g_form.getValue('sysparm_item_guid');
demo.addParam('sysparm_name', 'checkAttachment');
demo.addParam('sysparm_catalog_id', catalogItemID);
demo.getXMLWait();
var attachment=demo.getAnswer();
if(attachments == 'yes'){
return false; // true
} else if(attachment == 'no'){
alert('Please attach a file when the access require is specific');
return false;
}
}
// Service Portal
else {
var count = getSCAttachmentCount();
if(count <= 0) {
alert('Please attach a file when the access require is specific');
return false;
}
}
}
else {
return true;
}
}