- 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 09:29 PM
Hi @phil34 ,
Please change your catalog client script to the following:
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 == '1') {
alert("User Name already exists");
g_form.clearValue("u_email_address");
}
}
}
The correction is in the if(answer == '1')
This is because GlideAjax does not return true/false - it returns '1' for true and '0' for false.
Please let me know if this resolves your requirement, if yes, mark my answer as correct.
Please mark this post as a solution and also as helpful, if this resolves your issue or query.
Thanks,
Subhadeep Ghosh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2023 04:54 AM
Hi Kilo, for whatever reason Kiran's solution worked. I did try both