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

mihirlimje867
Tera Guru

Hello @Sakshi Lambat ,

1. Create a catalog client script either on onchange or onsubmit and in that you can call the script include with respective parameters 'mailbox email address' and 'login user sys_id'.
2. Create a script include with two parameter function and get the 'email' and 'user_sys_id' from the catalog client script. In this script include you can Glide the user table and get the user record using sys_id and then inside the 'if{}" block you can compare the email address for the Glide Record user and the mailbox email address then return the value according to your requirement.
3. Once the response is in the catalog client script you can abort the form submission or process.

Please like this reply if you think this will help you.

Thank you.

Hi @mihirlimje867 ,

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

Hello @Sakshi Lambat ,

Has it worked? if not could you send me the script include?

No, it is not working.

Below is the script include:

 

var SetDetails = Class.create();
SetDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

setUserDetails: function() {
var user = this.getParameter('sysparm_user_sys_id');
var gr_user = new GlideRecord('sys_user');
gr_user.get(user.toString());
var userObj = {};


userObj.location = gr_user.location.toString();
userObj.department = gr_user.department.toString();
userObj.manager = gr_user.manager.toString();


return JSON.stringify(userObj);


},