Apply logic on UI page and Catalog variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 06:53 AM
Hello All,
I have a custom UI page which is populated as UI Page variable in a catalog item as shown below
I need help with the below 2 points
1.When "OK" button is selected it has to check the email id from the "sys_user" table.
If email id is avaliable it has to redirect to another URL for example "https:dev88888.service-now.com/sp"
Variable name of UI page with email input is "email_id_uipage".
2. If not found ; it has to close and show other variables in the variable set.
Also, it has to take the email id entered in UI Page and set it to another variable from the variable set
Example. If "test@123.com" is entered from UI page variable and if email id does not exist in User table (after OK button is submitted) then that value should be passed to another variable "Email" as shown below
Need help to achieve the above 2 thanks.
UI Page
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div>
<form>
<label for="uemailid">Email</label>
<br><input type="text" id="uemailid" name="uemailid"></input></br>
</form>
<script>
</script>
<button onclick="addEmail()">Ok</button>
<button onclick="onCancel()">Cancel</button>
</div>
</j:jelly>
Querying server side with email (I have reference code) but need help on tweaking to satisfy the requirement
var gruser_list = new GlideRecord('sys_user');
gruser_list.addQuery('email',email_id_uipage);
gruser_list.query();
var results = [];
if(gruser_list.next())
{
return gruser_list.email;
}
TIA
@Allen Andreas @Ankur Bawiskar @Community Alums @SatyakiBose @priyasunku
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 01:45 AM
Like, I have the below script include and client script. However it is not working
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('checkEmailId');
ga.addParam('sysparm_name', 'checkAvailability');
ga.addParam('sysparm_check', newValue);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("User found" +answer);
//g_form.setValue('variable name',answer);
}
}
Script Includes
var checkEmailId = Class.create();
checkEmailId.prototype = {
initialize: function() {
},
checkAvailability: function() {
var value=this.getParameter('sysparm_check');
var grUseremail = new GlideRecord('sys_user');
grUseremail.addQuery('email',value);
grUseremail.query();
if(grUseremail.next()){
return grUseremail.email;
}
},
type: 'checkEmailId'
};
Also, I need help with point 2. To display other variables only if the email is not found. How to achieve the same.
TIA
@Ankur Bawiskar @Allen Andreas @Community Alums @priyasunku
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 01:55 AM
script include should be client callable. It seems your script include is not client callable
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 01:58 AM
script include
var checkEmailId = Class.create();
checkEmailId.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkAvailability: function() {
var value = this.getParameter('sysparm_check');
var grUseremail = new GlideRecord('sys_user');
grUseremail.addQuery('email',value);
grUseremail.query();
return grUseremail.hasNext();
},
type: 'checkEmailId'
});
client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('checkEmailId');
ga.addParam('sysparm_name', 'checkAvailability');
ga.addParam('sysparm_check', newValue);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer.toString() == 'false'){
alert('Email not found');
var url = ''; // give your URL here
top.window.open(url,"_blank");
}
else{
// show other variables
}
//g_form.setValue('variable name',answer);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 02:28 AM
Thank you, Ankur.
I ran into another problem now
I tried to control the visibilty via client script however, the Labels are still visible which has multiple check boxes. as shown below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setVisible('demo_variable_set', false);
//g_form.setDisplay('Demo_variable_set.dev_roles', false);
return;
}
var ga = new GlideAjax('checkEmailId');
ga.addParam('sysparm_name', 'checkAvailability');
ga.addParam('sysparm_check', newValue);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer.toString() == 'false'){
alert('Email not found');
g_form.setVisible('demo_variable_set', true);
}
else{
var url = "https://dev.....service-now.com/sp/?id=welcome_page1_crf"; // give your URL here
top.window.open(url,"_blank");
}
//g_form.setValue('variable name',answer);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 02:37 AM
so rest all is working fine?
just the labels are shown now?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader