If my variable is displayed -> set Attachment Mandatory

Jeff W NZAO B
Mega Guru

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

2 ACCEPTED SOLUTIONS

Jeff W NZAO B
Mega Guru

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

View solution in original post

Jeff W NZAO B
Mega Guru

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;
	}

}

View solution in original post

3 REPLIES 3

Anand Kumar P
Giga Patron
Giga Patron

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

Jeff W NZAO B
Mega Guru

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

Jeff W NZAO B
Mega Guru

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;
	}

}