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

Thanks @Ankur Bawiskar  That worked.

@matthew_hughes 

Glad to know.

Would you mind marking my response as correct?

Seems you marked your own response as correct by mistake.

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

@matthew_hughes 

Would you mind marking my response as correct?

Seems you marked your own response as correct by mistake.

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

Mark Manders
Mega Patron

Will this work:

 

var parentSysId = '';
var childSysId = fd_data.trigger.current.sys_id; // if it doesn't work, log the sysid to see what you get.
var relTypId = gs.getProperty('lbg.busApp.parent_child_relationship'); // Ensure this returns a sys_id!! add logging to be sure

var grCmdbRelCi = new GlideRecord('cmdb_rel_ci');
grCmdbRelCi.addQuery('child', childSysId);
grCmdbRelCi.addQuery('type', relTypId);
grCmdbRelCi.addQuery('parent.sys_class_name', 'cmdb_ci_business_app'); 
grCmdbRelCi.query();
if (grCmdbRelCi.next()) {
    parentSysId = grCmdbRelCi.getValue('parent'); // if it doesn't work, log the sys id to see what you get returned
}

return parentSysId;

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi @Mark Manders  I tried that and it stills on the right hand side as data unavailable