Search code examples
javascriptibm-mobilefirstworklight-adapters

Issues while passing parameters to Adaptor


I have a login form , which takes userid and password. When the user clicks on the submit button, the below js functions is called.

function getGeoCode(){
    var para=[$('#usernameInputField').val()];
    alert("from sql adapter"+para);

    var id = {username : para };
    var invocationData = {
        adapter: "GDMSDbAdaptor",
        procedure: "getGeoCode",
        parameters: [id]
    };
    alert("before adapter proc call");

    WL.Client.invokeProcedure(invocationData, {
        onSuccess: getMessage,
        onFailure: getMessageOnfailure
    });
    alert("after adapter proc call");
}

below adaptor code executes after the above function

var procedureStatement = WL.Server.createSQLStatement("SELECT DISP_NUMBER,DISP_STATUS,DISP_CREATE_DATE,CUST_CONT_NAME,DISP_RES_OWNER,DISP_MANAGER FROM GDMW.DISPUTE WHERE DISP_RES_OWNER IN (SELECT USER_CNUM FROM GDMW.USER_ACC_PROFILE WHERE USER_EMAIL=?)");

function getGeoCode(data) { 
    var email=data.username; 

    WL.Logger.info("In getGeoCode method"+email);
    return WL.Server.invokeSQLStatement({
        preparedStatement : procedureStatement,
        parameters : [email]
    });
}

Getting the below error when run the above code

[ERROR ] FWLSE0099E: An error occurred while invoking procedure [project GDMSLoginApp]GDMSDbAdaptor/getGeoCodeFWLSE0100E: parameters: [project GDMSLoginApp] TypeError: Cannot find default value for object. (C%3A%5Cnewworkspaceworklight%5CGDMSLoginApp%5Cadapters%5CGDMSDbAdaptor/GDMSDbAdaptor-impl.js#22) FWLSE0101E: Caused by: [project GDMSLoginApp]nullorg.mozilla.javascript.EcmaError: TypeError: Cannot find default value for object. (C%3A%5Cnewworkspaceworklight%5CGDMSLoginApp%5Cadapters%5CGDMSDbAdaptor/GDMSDbAdaptor-impl.js#22)

But it works fine when if I hardcode the parameter like below(email id):

function getGeoCode(){
    var para=[$('#usernameInputField').val()];
    alert("from sql adapter"+para);

    var id = {username : 'some@email.address' };
    var invocationData = {
        adapter: "GDMSDbAdaptor",
        procedure: "getGeoCode",
        parameters: [id]
    };

    alert("before adapter proc call");
    WL.Client.invokeProcedure(invocationData, {
        onSuccess: getMessage,
        onFailure: getMessageOnfailure
    });
    alert("after adapter proc call");
}

Is it something to do with the single quotes?


Solution

  • My first guess is that it is happening because you're using brackets:

    var para=[$('#usernameInputField').val()];
    

    When you should not:

    var para=$('#usernameInputField').val();
    

    And you could just as well do this probably:

    var id = {username : $('#usernameInputField').val() };