- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2024 03:31 AM
Hello Everyone,
I have a requirement involving two variables: "Email ID" and "Type of Access." The "Type of Access" variable is a reference field linked to the group table.
Here's the scenario: When a user enters their email ID and selects a type of access, the system needs to check if the email is already associated with any group or user records. If the email is found within the group or user records, it should trigger an alert message stating, "You are already present in the group. Please select another group." If the email is not found, the system should proceed to create a request.
Could anyone assist me with this?
Thank you,
Shareef
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2024 09:32 AM
Hello @shareef2 ,
You can write an onChange Client script on the field Type of Access and making call using GlideAjax to check the email is member of any group and achieve the requirement.
Try with the below. I have tested in my PDI and It's working fine for me.
// OnChange CS:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var email = g_form.getValue('email_id');
var access = g_form.getValue('type_of_access');
var ga = new GlideAjax('TestSI');
ga.addParam('sysparm_name','checkGrpMembership');
ga.addParam('sysparm_email',email);
ga.addParam('sysparm_group',access);
ga.getXML(callback);
function callback(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert("Ans:"+answer);
if(answer == 'true'){
alert("You are already member of the group please select a different group.");
g_form.clearValue('type_of_access');
g_form.addErrorMessage("Please select a group which you are not part of...");
}
}
}
//Script Include: TestSI
checkGrpMembership: function(){
var res = false;
var email = this.getParameter('sysparm_email');
var group = this.getParameter('sysparm_group');
//gs.info("Testing User Email:"+email+":Group:"+group);
var query = 'user.email='+email+'^group='+group;
//gs.info("Testing User Email query:"+query);
var getRec = new GlideRecord('sys_user_grmember');
getRec.addEncodedQuery(query);
getRec.query();
if(getRec.next()){
res = true;
}
return res;
},
Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2024 08:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2024 09:32 AM
Hello @shareef2 ,
You can write an onChange Client script on the field Type of Access and making call using GlideAjax to check the email is member of any group and achieve the requirement.
Try with the below. I have tested in my PDI and It's working fine for me.
// OnChange CS:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var email = g_form.getValue('email_id');
var access = g_form.getValue('type_of_access');
var ga = new GlideAjax('TestSI');
ga.addParam('sysparm_name','checkGrpMembership');
ga.addParam('sysparm_email',email);
ga.addParam('sysparm_group',access);
ga.getXML(callback);
function callback(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert("Ans:"+answer);
if(answer == 'true'){
alert("You are already member of the group please select a different group.");
g_form.clearValue('type_of_access');
g_form.addErrorMessage("Please select a group which you are not part of...");
}
}
}
//Script Include: TestSI
checkGrpMembership: function(){
var res = false;
var email = this.getParameter('sysparm_email');
var group = this.getParameter('sysparm_group');
//gs.info("Testing User Email:"+email+":Group:"+group);
var query = 'user.email='+email+'^group='+group;
//gs.info("Testing User Email query:"+query);
var getRec = new GlideRecord('sys_user_grmember');
getRec.addEncodedQuery(query);
getRec.query();
if(getRec.next()){
res = true;
}
return res;
},
Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2024 11:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2024 08:02 AM