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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2019 02:46 AM
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>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2019 02:54 AM
Hi
Can you show how youre calling the script include? Is it called from a scoped application?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2019 03:04 AM
Hi Omkar, sure. It's called from scoped application.
// sys_id is param passed from caller
function getGlideRecord(sys_id) {
var ga = new GlideAjax('get_ST'); //name of script include
ga.addParam('sysparm_name', 'getST_gr'); // name of funcion
ga.addParam('sysparm_sysid', JSON.stringify(sys_id)); // name param
return ga.getXMLAnswer(setSTValue);
}
// Callback to parse json from response of
function setSTvalue (response) {
return JSON.parse(response);
}
Anyway, that's work fine, I get the response from the server correctly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2019 03:09 AM
Hi
Why are going passing the sys_id with json stringify? This script doesnt give a clear idea of what is happening. Can you post the full script like from where this getGlideRecord function is called. Also check in your script include if you get value by doing gs.log("Value - "+this.getParameter("sysparm_sysid"));
Let me know.
Regards
Omkar Mone

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2019 03:26 AM
"Also check in your script include if you get value by doing gs.log("Value - "+this.getParameter("sysparm_sysid"));"
Yes, there is.
Anyway 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?
It's ok to put the string sys_id as param? If yes, because I got the error "Invalid GlideRecord input format found" ?