Skip to Content
0

Error when executing XSJS through XSJOB

Nov 02, 2017 at 01:27 PM

121

avatar image

Dear All,

I created xsjs (with the logic below) which works perfectly fine in browser.

But when I wrap the same logic in a function and execute it in xsjob, I receive an error at the last line in the below code - "Error: $.hdb.Connection.executeQuery: Parameter at position 2 is undefined which is not allowed".

Can you please suggest /advise on how to correct the error please ?

Thanks

Hari

var jobtyp = "T-001";
var company = "ART1";

var d 	= new Date();
var year = d.getFullYear();
var month = ('0' + (d.getMonth()+1)).slice(-2);
var date  = ('0' + d.getDate()).slice(-2);
var period = year + month;
var connection = $.hdb.getConnection();

var sqlstr    = "SELECT IND, PRD_ID, SCHD_DAY FROM \"<shema name>\".\"<Table Name>\" WHERE PRD_ID =? AND COMPANY = ? AND JOB_TYP = ?" ;
var exec      =  connection.executeQuery(sqlstr,period,company,jobtyp);
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Sergio Guerrero Nov 02, 2017 at 02:38 PM
-1

make sure your variables are set when you pass them to the function.

based on the error, as it states, it does not seem to be set prior to using it.

what is the code you have when you wrap this in a function? make sure the scope is ok

Show 6 Share
10 |10000 characters needed characters left characters exceeded

Hi Sergio,

I am just passing company to the function as a parameter in my xsjob. code snippet below is part of very same function. It is failing at the last line of the below snippet. Error message probably is hinting about period being undefined. Cant figure out why !

Thanks

function apicall(company){
var jobtyp = "T-001";
var d 	= new Date();
var year = d.getFullYear();
var month = ('0' + (d.getMonth()+1)).slice(-2);
var date  = ('0' + d.getDate()).slice(-2);
var period = year + month;
var connection = $.hdb.getConnection();

var sqlstr    = "SELECT IND, PRD_ID, SCHD_DAY FROM \"<shema name>\".\"<Table Name>\" WHERE PRD_ID =? AND COMPANY = ? AND JOB_TYP = ?" ;
var exec      =  connection.executeQuery(sqlstr,period,company,jobtyp);
}
0

is that is the case - then check for undefined/null when you call the function.

wherever you are calling the function you are not passing the value correctly, for example:

function apicall(company) {

// your code

}

/// somewhere else you are calling it...

apicall ( XXXXX ) ; // XXXXX is undefined at the moment you are calling the function.. .so trace XXXXX back and see where it is undefined. that should solve your problem... alternatively, pass a hardcoded value to test to verify then fix this instance (remove the hardcoded value after testing)

1

Hi Sergio,

You were right. It is working perfectly when I hardcode the value. Can you please suggest on how do I pass parameter value from xsjob to xsjs please ?

I am using below code for xsjob (pass CODE parameter with value US18):

{
    "description": "Outbound API",
    "action": "<path>:<xsjs file name>.xsjs::<apicall>",
    "schedules": [
       {
          "description": "Schedule",
          "xscron": "* * * * 01 01 10",
          "parameter": {
             "CODE": "US18"             }
       }
    ]
}

And below in xsjs function

function apicall(input){
var jobtyp = "T-001";
var d 	= new Date();
var year = d.getFullYear();
var month = ('0' + (d.getMonth()+1)).slice(-2);
var date  = ('0' + d.getDate()).slice(-2);
var period = year + month;
var connection = $.hdb.getConnection();

var sqlstr    = "SELECT IND, PRD_ID, SCHD_DAY FROM \"<shema name>\".\"<Table Name>\" WHERE PRD_ID =? AND COMPANY = ? AND JOB_TYP = ?" ;
var exec      =  connection.executeQuery(sqlstr,period,company,jobtyp);
}

How do I pass CODE parameter value(US18) from XSJOB into a variable (company) in xsjs please ? I know $.request.parameters.get does not work. I tried with var company = input.CODE ;(must be wrong as well). Can you please suggest ?

Thank you.

0

you need to know what is the initiator process? is it XSJS itself?

the xsjob will execute the xsjs function.. but... what triggers it is the question.

where is the value coming from? will the job get the value from the db? or a call from somewhere else?

0

Hi Sergio,

We have created xsjob(xs schedule) to initiate xsjs function periodically. apicall function in xsjs seeks for company value (expected to be passed dynamically).

I am trying to send this value as parameter from xsjob through parameter section but I must be doing something wrong in retrieving the parameter value passed by xsjob in xsjs.

Will be creating multiple xsjobs to run in different schedules and holding different company values (calling same xsjs service)

Thanks

0

Thanks Sergio. I was able to get it working after adding additional checks on validating input (for null or undefined).

1