- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 05:12 PM
Hi All,
I am sure someone has already done this, but I can't find a solution.
I have a catalogue item that is used to request an email address. The variable is "u_email_address"
When a user inputs an email address in that field I want to check if the email address already exists in the user table in our service now instance. This is what I want to happen when they are completing the form.
User types requested address in the field.
If the address entered by the user is already in the user table, then I want a message box to appear saying.
"The requested address is already in use"
When the user clicks on the OK button of the message box the text is cleared from the field and the user is required to enter another email address.
If they enter an email address that is NOT already in the user table then they can move to the next field.
I am new at scripting so I might need a bit of hand-holding if it is more complex. Hope you can help.
Cheers
Phil
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 09:03 PM - edited 07-10-2023 09:09 PM
Hey Phil,
You did almost right,
Use the below code in client script,
Hope it helps and please mark helpful if it solves the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 08:04 PM - edited 07-10-2023 09:09 PM
Hi @phil34 ,
This is an easy one for you.
1) Make use of onchange catalog client script, use glide ajax pass the value of email adress to the Script include.
2) In script include glide to user table compare the email address. If true return false or vice versa.
Hope it helps!.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 08:41 PM
Hi Kiran,
Thanks for answering, I have gone down that track and below is what I have configured but I cannot get it to behave, Regardless of what email address I put into the field the alert\message box always appears.
Maybe you can spot my mistake?
SCRIPT:
var Validate_Email = Class.create();
Validate_Email.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateEmail: function() {
var currentEmail = this.getParameter('sysparm_email');
var userGR = new GlideRecord('sys_user');
userGR.addQuery('email', currentEmail);
userGR.query();
if (userGR.next()) {
return true;
} else {
return false;
}
},
type: 'Validate_Email'
});
SCRIPT:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var usrGA = new GlideAjax('Validate_Email');
usrGA.addParam('sysparm_name', 'validateEmail');
usrGA.addParam('sysparm_email', newValue);
usrGA.getXMLAnswer(_result);
function _result(answer) {
if (answer) {
alert('User Name already exists');
g_form.clearValue('u_email_address');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 09:03 PM - edited 07-10-2023 09:09 PM
Hey Phil,
You did almost right,
Use the below code in client script,
Hope it helps and please mark helpful if it solves the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 09:18 PM
Hi @phil34
The answer which is returned from Server side is not "Boolean", but a string. Please modify your client script function accordingly.
************************************************************************
******************************************************