How I can set correctly input param GlideRecord to Flow invoked from Client

Botticelli
Kilo Contributor

The problem is:

 

UI invoke SubFlow through GlideFlow API, it's ok, but the input param of this subflow it's kind of GlideRecord of table (scoped application table).
Now, I aware that in the UI Client the 'only way' to work with GlideRecord is through GlideAjax calling ScriptInclude server-side.


What I done:


I wrote a function in my ScriptInclude which it will return me in Client-side the GlideRecord in JSON format, but as I expected it isn't work because is not a GlideRecord, but JSON (I suppose)..
So, another attempt I made was to set the input as string of sys_id. Putting the sys_id of that GlideRecord of table, I got an error from GlideFlow engine:

Invalid GlideRecord input format found


How to fix? Possible workoaround?


Since that isn't possibile to change the kind of SubFlow, I need a solution to make that in correct way... Any suggestion will be appreciated.
Thanks!

 

UPDATE: Script UI which invoke GlideFlow. 

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <script></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    </link>

    <div ng-app="ProjectWizard" class="jumbotron">
        <script>
            var myApp = angular.module('ProjectWizard', []);

            myApp.controller('VideoController', ['$http', function ($http) {
                var vm = this;
                vm.videoName = [];
                $http.defaults.headers.common.Accept = "application/json";

                // fill the select with a list of 'video'
                function autofillSelect() {
                    var ga = new GlideAjax('get_videoNames');
                    ga.addParam('sysparm_name', 'videoNames');
                    ga.getXMLAnswer(fill);
                }

                autofillSelect();

                // obtained the list, I put the list in the view
                function fill(response) {
                    vm.videoName = JSON.parse(response);
                    // console.log('data retrieved: '+JSON.stringify(vm.videoName));
                    return vm.videoName;
                }

                var inputs = {};
                vm.startFlow = function (selected) {
                    inputs['video_name'] = selected;
                    // !! it's type of string and it's ok, the sys_id is valorized
                    console.log('selected: ' + JSON.stringify(selected) + 'typeof ' + typeof selected);

                    GlideFlow.startSubflow('x_313310_video_appname.db_getallvideos', inputs)
                        .then(function (execution) {
                            return execution.awaitCompletion();
                        }, errorResolver())
                        .then(function (completion) {
                            var status = completion.status;
                            console.log('Completion status: ' + status);

                            // Available Outputs:
                            var outputs = completion.outputs;
                            console.log('completion output: ' + outputs);
                        }, errorResolver());
                }

                function getGlideRecord(sys_id) {
                    var ga = new GlideAjax('get_videoNames');
                    ga.addParam('sysparm_name', 'getVideoGR');
                    ga.addParam('sysparm_sysid', sys_id);
                    return ga.getXMLAnswer(setVideoValue); // Callback
                }

                function setVideoValue(response) {
                    return JSON.parse(response);
                }

            }]);

            function errorResolver(error) {
                console.error(error);
            }
        </script>
        <div ng-controller="VideoController as ctr">
            <div class="form-group">
                <select class="form-control" id="videos" ng-model="vm.selected"
                    ng-options="s.sys_id as s.title_name for s in ctr.videoName track by s.sys_id">
                    <option value="" disabled="true" selected="true">Please select a video</option>
                </select>
                <p>{{vm.selected}}</p>
            </div>

            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary" ng-click="ctr.startFlow(vm.selected)">Find video</button>

        </div>
    </div>
</j:jelly>
8 REPLIES 8

Hey @Botticelli 

you got any solution for this issue. Same issue I am facing.

I am calling my FLOW action using the catalog script script using  GlideFlow.startAction('abc', inputs)

as an input I need to pass the 'requested for' value to the flow action. 

In the flow action we have input variable defined of type "reference".

Rahul84_1-1675433126269.png

 

But when we are passing the sys_id input from the catalog client script , call isn't happening b/w catalog client script and action 

 

var inputs = {};
inputs['userid'] = 'ahiudwgqiuwbyuqgejkwqiu';

GlideFlow.startAction('abc', inputs)

 

when I m passing userid as hardcoded value sys_id of user , call isn't happening and it is throwing error -

Rahul84_0-1675433069777.png

can you pls let me know the best possible way to achieve this behavior.

thanks !

 

 

I updated the post with Client script for completeness

Ankur Bawiskar
Tera Patron

Hi,

If you can share the script that would be helpful

Regards

Ankur

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

Hi Ankur, I updated the post with the Client script.

Mine is not a practical difficulty, in sense that I've not difficult to write script... Any communication from client-side and server-side it's fine, no problem. My question regards the "How to do" in my use case described above?

I mean, If a definition of SubFlow expect a input of GlideRecord, and the Client UI it isn't have that GlideRecord (but have his sys_id), what's the best way to put this value as param input to the flow?

This is the UI script when I invoke the SubFlow:

vm.startFlow = function (selected_sysid) {
    inputs['input_name'] = selected_sysid;
    // it's a string sys_id
    console.log('selected: ' + JSON.stringify(selected_sysid) + 'typeof ' + typeof selected_sysid);
    GlideFlow.startSubflow('scopedname.flowname', inputs)
        .then(function (execution) {
            return execution.awaitCompletion();
        }, errorResolver())
        .then(function (completion) {
            var status = completion.status;
            console.log('Completion status: ' + status);

            // Available Outputs:
            var outputs = completion.outputs;
            console.log('completion output: ' + outputs);
        }, errorResolver());
}