Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to look up record with a condition script?

LinhN
Tera Contributor

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

LinhN_2-1724311039080.png

 

 

 

 

4 REPLIES 4

Sandeep Rajput
Tera Patron

@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?

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

LinhN_0-1724314180945.png

 

 

@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;

Sorry, but it didn't work with this.