Form submission should restrict if Requested By's email address does not match the entered email.

Sakshi Lambat
Tera Contributor

In one of the catalog items, I am having a filled mailbox type, and in that I am having the option as personal mailbox. So if I select the personal mailbox, then there is another field that is the mailbox email address. So if the requested by is raising that request, then in the mailbox email address field, if that requested by user's email address is present, then user should be able to submit the form. But if that mailbox email address is not matching with the requested by's email address, then the user should not be able to submit the form.

So can you please help me to implement this

7 REPLIES 7

Jordan Vignoni
Tera Guru

So, the catalog item can only be submitted when the "Requested by" email address matches the email address entered in the "Mailbox email address" field?  You could try an onChange client script on the required "Mailbox email address" field.  If the value does not match the "Requested by" email address, display an alert and clear the value in the "Mailbox email address" field.

Hi @Jordan Vignoni,

I am using this onSubmit Client Script

 

function onSubmit() {
var mailboxType = g_form.getValue('mailbox_type');
var mailboxEmail = g_form.getValue('mailbox_email_address');
var requestedBy = g_form.getValue('requested_for');

var gr = new GlideAjax('global.SetDetails');
gr.addParam('sysparm_name', 'setemailID');
gr.addParam('sysparm_emailID', requestedBy);
gr.getXML(getResponse);
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer');
g_scratchpad.isFormValid = values;
 
}
//alert(g_scratchpad.isFormValid);

if (g_scratchpad.isFormValid != mailboxEmail) {
g_form.addErrorMessage('The Mailbox Email Address must be the same as the Requested By user’s email for a Personal Mailbox.');
return false;
}

return true;
}

I would try using an onChange client script like this one, and have the "Variable name" be mailbox_email_address:

Screenshot 2024-09-04 at 12.37.47 PM.png