Validation for MVRS variable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2023 08:54 AM
Hi Team,
We have a MVRS variable set on the catalog item form to add users in to the sys_user table, with variables as First Name, Last Name, Email. Now I need to check if the user present in user table using email variable from MVRS, if the user exists in the table then I need to show an alert saying that user already exists, if not allow user to submit the request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2023 09:13 AM - edited ‎08-29-2023 09:17 AM
Hello @Gowtham29 ,
You can write an on change client script inside MVRS which will call a script include to check in user table that if any user has the same email id .
Client script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var user = g_form.getValue('your_email_id_variable_backend_name');
//Call script include
var ga = new GlideAjax('checkUserDetails'); //Scriptinclude
ga.addParam('sysparm_name', 'getUserDetails'); //Method
ga.addParam('userId',user); //Parameters
ga.getXMLAnswer(getResponse);
function getResponse(response){
if(response==true||response=="true")
{
alert("User Already exists in database");
g_form.clearValue('your_email_field_backend_name');
return false;
}
}
}
Script include :Make sure your scirpt include name is checkUserDetails
var checkUserDetails = Class.create();
checkUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails: function(){
var userId = this.getParameter('userId');
var grSysUser = new GlideRecord('sys_user');
grSysUser.addQuery('email',userId);
grSysUser.query();
if (grSysUser.next()) {
return true;
}
else
{
return false;
}
},
type: 'checkUserDetails'
});
Hope this helps
Mark the answer correct if this helps you
Thanks