How to look up record with a condition script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 12:21 AM
Hi guys, I have a sub-flow and I want to use a script to look up records based on a condition. I am using a script to add a condition. Before, I used a specific sys_id to retrieve the record and it worked. But after considering that sys_id is different between the developing environment and the production environment. So I want to change to using the name of the input. The condition here is comparing with the records in the sys_properties table. For example, the name is Voucher A, the record in sys_properties is Balance A. When coming to the if condition, it returns a false value though I have converted the value from string to number. Can you help me with this case? How can I compare the input with the string?
The voucher type is a reference field to a table
var input = fd_data.subflow_inputs.voucher.name ;
gs.info('input value' + input);
var condition;
var gr = new GlideRecord('sys_properties');
if (input === 'Voucher A') {
gr.addQuery('name', ' balance A');
} else if (input === 'Voucher B') {
gr.addQuery('name', 'balance B');
} else if (input === 'Voucher C') {
gr.addQuery('name', 'balance C');
}
gr.query();
if (gr.next()) {
condition = gr.getValue('name');
gs.log('Property found: ' + condition);
} else {
gs.log('No property found for input: ' + input);
}
return condition;
The value returns false

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 01:01 AM
@LinhN How are you executing this script in the subflow? Via a custom action? If yes then are you assigning the condition to an output variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 01:10 AM
I am executing this script in the subflow. This script is used on Look-up record action with condition. I'll use the result of this look-up record action for the If condition logic. The lookup record value (2) returns false

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 01:36 AM
@LinhN Could you try the following and see if it works.
var input = fd_data.subflow_inputs.voucher.name.toString();
gs.info('input value' + input);
var condition='';
var gr = new GlideRecord('sys_properties');
if (input === 'Voucher A') {
gr.addQuery('name', ' balance A');
} else if (input === 'Voucher B') {
gr.addQuery('name', 'balance B');
} else if (input === 'Voucher C') {
gr.addQuery('name', 'balance C');
}
gr.query();
if (gr.next()) {
condition = gr.getValue('value');
gs.log('Property found: ' + condition);
} else {
gs.log('No property found for input: ' + input);
}
return condition;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 02:46 AM
Sorry, but it didn't work with this.