Value assignment issue

LabKey Support Forum (Inactive)
Value assignment issue bront  2015-04-29 09:42
Status: Closed
 
Feifei,

I am not entirely sure, but I think you have a scope issue.

You could place the alert() within the success function:

 function onSuccess(data)
    {
        requirementId = data.rows[data.rowCount-1].Name;
        alert(requirementId);
    }

Or you could pass the requirementId to an external function:

var requirementId;
    
LABKEY.Query.selectRows({
        schemaName: 'lists',
        queryName: 'Main List',
    success: onSuccess,
    failure: onFailure
    });
    
function onSuccess(data)
    {
      requirementId = data.rows[data.rowCount-1].Name;
      tester(requirementId);
    }
    
function onFailure(errorInfo, options, responseObj)
    {
    if (errorInfo && errorInfo.exception)
      alert("Failure: " + errorInfo.exception);
    else
      alert("Failure: " + responseObj.statusText);
    }
    
alert(requirementId); // undefined

// new function
function tester(reqId) {
    console.log('requirementId' + reqId); // defined
}


I hope this might be of some help.

cheers,

bront