- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2017 01:51 PM
Hi,
I have a Training Class Registration application with Attendee,Training Class, & Training Room tables. A Record Producer form (on Attendee table) allows someone to register for a Class by entering the Attendee Name and selecting a Training Class. The Attendee Name variable references the User table. The Training Class variable references the Training Class table. Training Class variable is mapped to the Training Class table and already includes a reference qualifier (java script call to script includes) that sets the filter to only show Classes with a Status of "Open".
I have a new requirement to check if an Attendee has already registered for a Class that they are trying to select again. Before the Record Producer is submitted, I would need to check the Training Class (sys id) selected against the Attendee Name (User sys id) selected and I assume query the Class related list of Attendees to check if the Attendee sys id is listed. If a match is found, show alert that "Attendee has already registered".
Can this be done in a Business Rule with glide query or is there another way to accomplish it? Any insight into how to do this would be greatly appreciated.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2017 11:07 AM
One more correction and you are all set.
var RegisterAttendee = Class.create();
RegisterAttendee.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAttendee: function() {
gs.log('++++++++++Inside the script include++++++++++++++');
var an = this.getParameter('sysparm_attendee_name');
var tc = this.getParameter('sysparm_class_name'); // Correction
var att = new GlideRecord('u_attendee');
gs.log('++++++++++tc ++++++++++++++'+tc );
gs.log('++++++++++an ++++++++++++++'+an);
att.addQuery('u_attendee_name',an+'');
att.addQuery('u_training_class',tc+'');
att.query();
if(att.next()){
gs.log('++++++++++Inside the if statement+++++++++att.u_attendee_name+++++'+att.u_attendee_name);
if(att.u_attendee_name == an && att.u_training_class == tc){
return true;
}
else {
return false;
}
}
return false; // Added a return false here
}, // you missed a comma here
type: 'RegisterAttendee'
});
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2017 02:06 PM
You can find some helpful examples in 2.1 below.
http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 12:08 PM
Thank you both for getting me started. I'm struggling with this one, however. Below is the Client Script & Script Includes that are not working. Wondering if you could kick me in the right direction.
What I need the script to do on Record Producer when an Attendee Name (reference field to User table) is selected and a Training Class (reference field to Training Class table) is selected:
- Get the sys_id of the Attendee Name selected on the RP form
- Get the sys_id of the Training Class selected on the RP form
- Check that the Related Attendees List of the Training Class (sys_id) selected on the form doesn't already contain the Attendee (sys_id) of the Attendee Name selected on the form.
- If the Training Class does already have the Attendee in the Related Attendee List, prompt with alert message ("Attendee is already Registered).
Client Script
function onSubmit(){
var attendee = g_form.getReference('sys_id'.u_attendee_name);
var trClass = g_form.getReference('sys_id'.u_training_class);
var ga = new GlideAjax('RegisterAttendee');
ga.addParam('sysparm_name','getAttendee');
ga.addParam('sysparm_attendee_name',attendee);
ga.addparm('sysparm_class_name',trClass);
ga.getXMLWait();
if(ga.getAnswer()=="false"){ //add the attendee;
}else{
alert("The Attendee you are trying to enter is already registered for this Class.");
}
}
Script Includes
var RegisterAttendee = Class.create();
RegisterAttendee.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAttendee: function() {
var an = this.getParameter('sysparm_attendee_name');
var tc = this.getParameter('sysparm.class_name');
var att = new GlideRecord('u_attendee');
att.addQuery('u_attendee_name',an);
att.addQuery('u_training_class',tc);
att.query();
if(att.next()){
if(att.u_attendee_name == an && att.u_training_class == tc){
return true;
}
else {
return false;
}
}
}
//type: 'RegisterAttendee'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 12:13 PM
Your client script is wrong. I added another alert to check if it returns any value or not. Also make the script include Client callable.
function onSubmit(){
var attendee = g_form.getValue('u_attendee_name');
var trClass = g_form.getValue('u_training_class');
var ga = new GlideAjax('RegisterAttendee');
ga.addParam('sysparm_name','getAttendee');
ga.addParam('sysparm_attendee_name',attendee);
ga.addparm('sysparm_class_name',trClass);
ga.getXMLWait();
alert('=============my ga.getAnswer() is ========='+ga.getAnswer());
if(ga.getAnswer()=="false"){ //add the attendee;
}else{
alert("The Attendee you are trying to enter is already registered for this Class.");
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 12:25 PM
Script Include is Client callable. I changed the Client script. Nothing happens when I click Submit. No alert, No submit...nothing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 12:28 PM
Try below script and let me know, if you get some alert. make sure the field names are correct for u_attendee_name and u_training_class
function onSubmit(){
var attendee = g_form.getValue('u_attendee_name');
var trClass = g_form.getValue('u_training_class');
alert('+++++++++attendee '+attendee );
alert('+++++++++trClass '+trClass );
var ga = new GlideAjax('RegisterAttendee');
ga.addParam('sysparm_name','getAttendee');
ga.addParam('sysparm_attendee_name',attendee);
ga.addparm('sysparm_class_name',trClass);
ga.getXMLWait();
alert('=============my ga.getAnswer() is ========='+ga.getAnswer());
if(ga.getAnswer()=="false"){ //add the attendee;
}else{
alert("The Attendee you are trying to enter is already registered for this Class.");
}
}
Please mark this response as correct or helpful if it assisted you with your question.