Error with calling script include in flow designer

Smriti Rastogi
Kilo Guru

I have a script include with this syntax 

var testScriptInclude = Class.create();
testScriptInclude.prototype = {
            initialize: function(currentObj) {
            this.currentRecord=currentObj;
},

generateDataFields:function(){
var fields = {
'dataone':'',
'datatwo':''
}
// some logic to populate data1 & data2

return fields

I am calling this in inline script in flow designer - 

var obj=new global.testScriptInclude(fd_data.trigger.current);
var data = obj.generateDataFields();
return data['dataone'];
 
Error: undefined is not a function.,Detail: undefined is not a function.
 
Any clue what I am doing wrong.
 
Also the same works in background script.
11 REPLIES 11

Maik Skoddow
Tera Patron

Hi

basically it looks good. Is the Flow in the Global scope or in a Custom Scope?

Do you have a more detailed log for us? In which line exactly was the error?

Kind regards
Maik

The flow is in another scope .

The script include is set as accessible from all application scopes.

I tried using log statements inside my generateDataFields function.

try{

     //some logic

     gs.log("data dictionary set");

}

catch(e){
     gs.log("error in setting data dictionary" + e.message);
}

Both the log statements are not getting printed.

Hitoshi Ozawa
Giga Sage

There's probably an error in "// some logic to populate data1 & data2" section so the function generateDataFields() is not returning anything because of the error. Since nothing is being returned, calling "['dataone']" is creating an error.

2 things to do.

1. add a try - catch clause in the script include.

        var fields = {
            'dataone': '',
            'datatwo': ''
        };
		try {
			// 
		} catch (e) {
			gs.error(e.message);
		}
		return fields;

2. check if the returned value is valid before calling "['dataone']"

var obj=new global.testScriptInclude();
var data = obj.generateDataFields();
if (typeof data != 'undefined') {
  return data['dataone'];
}
return;

I tried using log statements inside my generateDataFields function.

try{

     //some logic

     gs.log("data dictionary set");

}

catch(e){
     gs.log("error in setting data dictionary" + e.message);
}

Both the log statements are not getting printed.