How to apply a SYS ID from a piece of code within the Look Up record action of flow designer?

matthew_hughes
Kilo Sage

In my Flow Designer flow, I'm trying to query the u_bia_response table based on the parent sys ID of a business application which has a certain relationship type with the current child business application. I'm trying to extract the parent business application sys ID as below:

 

/*
**Access Flow/Action data using the fd_data object. Script must return a value.
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/

var parent = new GlideRecord('cmdb_ci_business_app');

        // sys id of business application parent child relationship type
        var relTypId = gs.getProperty('lbg.busApp.parent_child_relationship');

        var ciRel = new GlideRecord('cmdb_rel_ci');
        ciRel.addQuery('child', fd_data.trigger.current);
        ciRel.addQuery('type', relTypId);
        ciRel.addQuery('parent.sys_class_name', 'cmdb_ci_business_app');
        ciRel.query();

        // if relationship found
        if (ciRel.next()) {
            // get parent Business Application
            if (parent.get(ciRel.getValue('parent'))) {
                var parentSysId = parent.getValue('sys_id');
                return parentSysId;
            }
            }
 
 
However, what I'm wanting to do is the use the value of 'parentSysId' in a formula of a Look Up record action, so it would be:
 
Business Application.Sys ID is parentSysId
 
Does anyone what I can do to achieve this because at the moment, it's selecting the first record in the u_bia_response table rather than the record where the related Business Application is parentSysId
2 ACCEPTED SOLUTIONS

Hi @Ankur Bawiskar 

I'm trying to use it here:

matthew_hughes_0-1739350100514.png

 

View solution in original post

@matthew_hughes 

So did the flow variable store the correct sysId as per change I suggested?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

14 REPLIES 14

Sandeep Rajput
Tera Patron
Tera Patron

@matthew_hughes You need to define a flow variable in this case. This flow variable can be set via the output of your script mentioned in the question above.

 

The flow variable then can be used in the Look up record action for comparison. 

Hi @Sandeep Rajput I've got my flow variable set up to a string:

matthew_hughes_0-1739284303287.png

 

How would I then apply that with my code?

@matthew_hughes You need to use set Flow Variable step to set the flow variable. For more information please refer to https://www.servicenow.com/docs/bundle/yokohama-build-workflows/page/administer/flow-designer/concep...

Hi @Sandeep Rajput 

 

I've done the following:

 

matthew_hughes_1-1739285216490.png

 

 

How I can't seem to select it on the right hand side. Do you know why that could be?