How to return the results of flow designer action from script include?

JLeong
Mega Sage

Hi Guys,

Need some help...

I created a flow action to get user's telecom asset(s). The action is very simple and it works. It returns the sys_id of the assets: 

TelecomAsset.png

And below is the script include:
 

var MobilityUtil = Class.create();
MobilityUtil.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

getDevice: function() {

try {
var sysID = this.getParameter('sysparm_id');
var user_GR = new GlideRecordSecure('sys_user');
user_GR.addQuery('sys_id', sysID);
user_GR.query();
user_GR.next();

var inputs = {};
inputs['user'] = user_GR; // GlideRecord of table: sys_user

var result = sn_fd.FlowAPI.getRunner().action('x_rrdu2_mobility.get_telecom_asset').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();

// Get Outputs:
var device = outputs['device']; // String
gs.info('Device = ' + device);
return device;

} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
},

type: 'MobilityUtil'
});

 

How do I return the list of devices?  I am currently getting Device = [object GlideRecord]

 

Thank you!

 

 

 

1 ACCEPTED SOLUTION

Tushar
Kilo Sage
Kilo Sage

Hi @JLeong 

 

I hope this helps -

 

var MobilityUtil = Class.create();
MobilityUtil.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getDevice: function() {
    
        try {
            var sysID = this.getParameter('sysparm_id');
            var user_GR = new GlideRecordSecure('sys_user');
            user_GR.addQuery('sys_id', sysID);
            user_GR.query();
            user_GR.next();
    
            var inputs = {};
            inputs['user'] = user_GR; // GlideRecord of table: sys_user
    
            var result = sn_fd.FlowAPI.getRunner().action('x_rrdu2_mobility.get_telecom_asset').inForeground().withInputs(inputs).run();
            var outputs = result.getOutputs();
    
            // Get Outputs:
            var devices = [];
            for (var i = 0; i < outputs['device'].length; i++) {
                devices.push(outputs['device'][i].sys_id);
            }
    
            // Print Devices:
            for (var i = 0; i < devices.length; i++) {
                gs.info('Device ' + i + ': ' + devices[i]);
            }
    
            return devices;
    
        } catch (ex) {
            var message = ex.getMessage();
            gs.error(message);
        }
    },
    
    type: 'MobilityUtil'
});

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

View solution in original post

2 REPLIES 2

Tushar
Kilo Sage
Kilo Sage

Hi @JLeong 

 

I hope this helps -

 

var MobilityUtil = Class.create();
MobilityUtil.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getDevice: function() {
    
        try {
            var sysID = this.getParameter('sysparm_id');
            var user_GR = new GlideRecordSecure('sys_user');
            user_GR.addQuery('sys_id', sysID);
            user_GR.query();
            user_GR.next();
    
            var inputs = {};
            inputs['user'] = user_GR; // GlideRecord of table: sys_user
    
            var result = sn_fd.FlowAPI.getRunner().action('x_rrdu2_mobility.get_telecom_asset').inForeground().withInputs(inputs).run();
            var outputs = result.getOutputs();
    
            // Get Outputs:
            var devices = [];
            for (var i = 0; i < outputs['device'].length; i++) {
                devices.push(outputs['device'][i].sys_id);
            }
    
            // Print Devices:
            for (var i = 0; i < devices.length; i++) {
                gs.info('Device ' + i + ': ' + devices[i]);
            }
    
            return devices;
    
        } catch (ex) {
            var message = ex.getMessage();
            gs.error(message);
        }
    },
    
    type: 'MobilityUtil'
});

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

I appreciate your help, Tushar! Thank you!