- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2014 02:40 PM
Hello Implement,
Table created called u_roster with two fields: Name and Round_rob_val.
All round_rob_val values set to zero.
Just trying to get a query going that will return a name and
write it to the log.
The code is in the Advanced Script section of a Create Task Activity
in a Workflow that is launched by creating a new Incident.
// get the name of any person on roster whose round_rob_val is equal to zero
var round_robin_var = new GlideRecord('u_roster');
round_robin_var.addQuery('Round_rob_val', 0);
round_robin_var.query(); // Issue the query to the database to get relevant records
while (round_robin_var.next()) {
// add code here to process the incident record
var round_robin_name = u.roster.Name;
var rr_msg = "The roster name is " + round_robin_name;
gs.log(rr_msg);
}
In other examples seen the gs.log() method is in the curly brackets
after the 'while' statement.
I think maybe the problem is in
var round_robin_name = u.roster.Name;
But have seen other code where after the record has been fetched
it works to dot walk to the value needed.
Any ideas what the problem is?
Thanks.
Allen Pitts
LHP Hospital Group
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2014 03:47 PM
I see two problems in this code and I have noted where those are. Remember to to as Jim Coyne (CompuCom) says and add the "u_" for custom made fields.
// get the name of any person on roster whose round_rob_val is equal to zero
var round_robin_var = new GlideRecord('u_roster');
round_robin_var.addQuery('u_round_rob_val', 0); (1)//Since this is a custom table then these are custom field names. They start with "u_"
round_robin_var.query(); // Issue the query to the database to get relevant records
while (round_robin_var.next()) {
// add code here to process the incident record
var round_robin_name = round_robin_var.u_name;(2)
var rr_msg = "The roster name is " + round_robin_name;
gs.log(rr_msg);
}
Does this help a little?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2014 02:47 PM
This is just after a real quick read of the post, and you are correct, the problem is your line:
var round_robin_name = u.roster.Name;
...should actually be:
var round_robin_name = round_robin_var.getValue("u_name");
"round_robin_var" is your GlideRecord object, so you need to use it when referencing a field name and not the table name. And the field name should be lowercase. And it is always good practice to use the "getValue()" method.
EDIT: changed the field name to "u_name" because this is a custom table, so all fields would be "u_" something.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2014 03:47 PM
I see two problems in this code and I have noted where those are. Remember to to as Jim Coyne (CompuCom) says and add the "u_" for custom made fields.
// get the name of any person on roster whose round_rob_val is equal to zero
var round_robin_var = new GlideRecord('u_roster');
round_robin_var.addQuery('u_round_rob_val', 0); (1)//Since this is a custom table then these are custom field names. They start with "u_"
round_robin_var.query(); // Issue the query to the database to get relevant records
while (round_robin_var.next()) {
// add code here to process the incident record
var round_robin_name = round_robin_var.u_name;(2)
var rr_msg = "The roster name is " + round_robin_name;
gs.log(rr_msg);
}
Does this help a little?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2014 08:34 AM
Jim and Casey,
Thanks for your help and the spot on answers.
When the corrected code was run thirteen
entries were made to the log. That makes sense because there are thirteen
u_name/u_round_rob_val pairs in the table.
But the process requires that only value be returned. That value returned should
be any one field where the u_round_rob_val is equal to the lowest u_round_rob_val.
So the code was modified
// get the name of any person on roster whose round_rob_val is equal to the lowest round_rob_val
var round_robin_var = new GlideRecord('u_roster');
// line added to put fields in ascending order by 'u_round_rob_val'
round_robin_var.orderBy('u_round_rob_val');
// line added to only return the first field
round_robin_var.setLimit(1);
round_robin_var.addQuery('u_round_rob_val', 0);
round_robin_var.query(); // Issue the query to the database to get relevant records
while (round_robin_var.next()) {
// add code here to process the incident record
var round_robin_name = round_robin_var.u_name;
var rr_msg = round_robin_name;
gs.log(rr_msg);
}
The two line added are marked //line added...
This works
Thanks again
Allen Pitts
LHP Hospital Group