Subflow code snippet is not working in script include

JLeong
Mega Sage

Hi Guys,

 

Looks like I am missing something. I have a simple subflow that I am calling from a script include and it's not working.

 

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var usersysID = g_form.getValue('mobility_request_for');
    var deviceCount = checkDeviceCount(usersysID);
}
 
function checkDeviceCount(usersysID) {
alert('checkDeviceCount');
    var deviceCnt = new GlideAjax('MobilityUtils');
    deviceCnt.addParam('sysparm_name', 'countDevice');
    deviceCnt.addParam('sysparm_id', usersysID);
    deviceCnt.getXML(getDeviceCount);
}
 
function getDeviceCount(response) {
alert('getDeviceCount');
    var answer = response.responseXML.documentElement.getAttribute('answer');
alert(answer);
}

------------------------

 

Script Include

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

countDevice: function() {
try {
//gs.info('deviceCount', 'Mobility');
var userSysID = this.getParameter('sysparm_id');
//gs.info('userSysID = ' + userSysID, 'Mobility');

var inputs = {};
inputs['user_sysid'] = userSysID; // GlideRecord of table: sys_user

var result = sn_fd.FlowAPI.getRunner().subflow('x_rrdu2_mobility_e.mobility__number_of_devices_own_by_the_user').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();

var devicecount = outputs['devicecount']; // Integer
//gs.info('devicecount = ' + devicecount, 'Mobility');
return devicecount;

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


type: 'MobilityUtils'
});

Thank you in advance!
1 ACCEPTED SOLUTION

Hi Tony,

 

I got an error - "Invalid GlideRecord input format found"

 

Then I found this article - https://www.servicenow.com/community/developer-forum/invalid-gliderecord-input-format-found/td-p/253...

 

This fixed the issue.

 

I changed my script to add the GlideRecord part:

JLeong_0-1690572448345.png

 

 

View solution in original post

4 REPLIES 4

Tony Chatfield1
Kilo Patron

Hi, what are the results of your investigation\diagnostics? Have you confirmed that your client script is triggered, the GlideAjax call is made and that the GlideAjax function runs? Have you confirmed that your script-include is client callable, that the values passed in by your gliadeAjax parameter is correct and that the correct value is set in 'inputs'
Does your flow call complete\return any results, good or bad?

Hi Tony,

 

Thanks for responding to my question.

The client script is being triggered and I get a null as the answer. However, I don't see any executions on the subflow. When I run a test in the subflow it works.

I added logs in the script include, but I dont see any log. For scope application does gs.log works? I also tried to hardcode the parm being sent to script include and it is still not working. 

 

I also tried to run the subflow code snippet in the background script and it also doesn't work, but then again the subflow works by itself.

 

Hi, I would expect logging\info messages to work in the script-include.
Did you add ACL\assign suitable role to the script-include (normally via popup on save).
Is the usage in the same scope, is the script-includes 'Acessible from' field set correctly.
Have you tried setting the full API name for the ajax scripts sysparm_name value on client script
'global.countDevice' or (I am guessing) 'x_rrdu2_mobility_e.countDevice'

Hi Tony,

 

I got an error - "Invalid GlideRecord input format found"

 

Then I found this article - https://www.servicenow.com/community/developer-forum/invalid-gliderecord-input-format-found/td-p/253...

 

This fixed the issue.

 

I changed my script to add the GlideRecord part:

JLeong_0-1690572448345.png