How to return the right record from the script condition in action Lookup Record in Flow Designer

LinhN
Tera Contributor

Hi guys, I am writing a script to add a condition for lookup Record. 

I have a sub-flow with the input of a variable reference to a table (kind)

The script as below 

var inputSysId = fd_data.subflow_inputs.kind;
gs.info('Input value: ' + inputSysId);
var inputName;
var condition;
var grmodel = new GlideRecord('cmdb_model');

if (inputSysId) {
    if (grmodel.get(inputSysId)) {
        inputName = grmodel.getValue('name');
        gs.info('Input name: ' + inputName);
    } 
} 

var gr = new GlideRecord('sys_properties');

if (inputName == 'common') {
    gr.addQuery('name', 'common_balance');
} else if (inputName == 'medium') {
    gr.addQuery('name', 'medium_balance');
} else if (inputName == 'advance') {
    gr.addQuery('name', 'advanced_balance');
}

gr.query();
if (gr.next()) {
    condition = gr.getValue('name');
    gs.info('Property found: ' + condition);
} else {
    gs.info('No property found for input: ' + inputName);
}
gs.info('Condition to be used: ' + condition);
return condition;

  But it now returns a different record from sys_properties table. I want to return the record which is as sam as the condition I found. How can I return it right?   

LinhN_0-1724753666280.png

 

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@LinhN Did you try to run the same query using a background/fix script? If not, can you try to replicate the same query via a background script and see what condition it prints in the logs?

Yes, I've already tried with scripts-background and it printed the expected result. But when applying to lookup records, it returned a different record of sys_properties table glide.ui.specify.dbname; Could you help me know the reason of this?

@LinhN Please test the following and see if it works.

 

var inputSysId = fd_data.subflow_inputs.kind+'';
gs.info('Input value: ' + inputSysId);
var inputName;
var condition;
var grmodel = new GlideRecord('cmdb_model');

if (inputSysId) {
    if (grmodel.get(inputSysId)) {
        inputName = grmodel.getValue('name');
        gs.info('Input name: ' + inputName);
    } 
} 

var gr = new GlideRecord('sys_properties');

if (inputName.trim() == 'common') {
    gr.addQuery('name', 'common_balance');
} else if (inputName.trim() == 'medium') {
    gr.addQuery('name', 'medium_balance');
} else if (inputName.trim() == 'advance') {
    gr.addQuery('name', 'advanced_balance');
}

gr.query();
if (gr.next()) {
    condition = gr.getValue('name');
    gs.info('Property found: ' + condition);
} else {
    gs.info('No property found for input: ' + inputName);
}
gs.info('Condition to be used: ' + condition);
return condition;

Made slight changes to your script, please check if they work.