
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 11:47 AM
I am trying to create a business rule that queries a second table for any entries (based on user).
If records found, I need to create a new record that second table with an incremental code.
If NO records are found for that user, I need to add a record.
What I can't seem to figure out is the second part.
I can get the query to run and add additional records associated to the user, but I cannot figure out how to run the secondary code to insert when no records returned from the query.
Below is one attempt. If the user is not in the second table, I can never get the to the else code (or log message).
I don't recall ever attempting a no records returned type query before, so not sure how to proceed.
userPh.query();
if(userPh.next()){
phCode.push(userPh.u_phone_code.toString());
createUserPhoneRecord();
}
else{
gs.log('got to the else');
createNewUserPhoneRecord();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 01:32 PM
Whats your query lines before userPh.query()
add some logs, before the if statement
gs.log(userPh.getEncodedQuery());
gs.log(userPh.getRowCount());
Those may both provide clues. My guess would be the query is not formatted correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 01:37 PM
where did you assign current.assigned_to??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 01:46 PM
assigned_to is from the current record that is being inserted. On insert, I am querying the u_user_phone table for the user in that field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 01:51 PM
In this code the query get 0, so it print im out so probably the query is wrong
var userPh = new GlideRecord('sys_user');
userPh.addQuery('name', "admin");
userPh.query();
gs.print(userPh.getRowCount());
if(userPh.getRowCount() != 0) {
gs.print(userPh.getRowCount());
} else {
gs.print("i'm out");
}
This code gets in
var userPh = new GlideRecord('sys_user');
userPh.addQuery('sys_id', gs.getUserID());
userPh.query();
gs.print(userPh.getRowCount());
if(userPh.getRowCount() != 0) {
gs.print(userPh.getRowCount());
} else {
gs.print("i'm out");
}
get a print of the current.assigned_to, also, the u_user is a ref field, because if it is, then you need the sys_id not the name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 01:26 PM
Can you please show us the code before the line: userPh.query();
The problem most likely lies in the original query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 01:32 PM
Whats your query lines before userPh.query()
add some logs, before the if statement
gs.log(userPh.getEncodedQuery());
gs.log(userPh.getRowCount());
Those may both provide clues. My guess would be the query is not formatted correctly.