Jayesh Acharya
asked on
javascript variable ReferenceError: DataFound is not defined
I have created a javascript function but I have having trouble with a variable that is not aviable to me when later on in the function
now I know that the tableService.queryEntities piece works as the log file shows me a value of
DataFound 2= YES
but I get an error at the line
its complaingin that it cant find the value DataFound.
now I tried to define this variable outside of the tableService.queryEntities , but then what I got was the value that I intialized DataFound.
so I need some help in making sure I can pass this value of YES or NO that is contained in "DataFound" to the calling function
..
..
tableService.queryEntities
( 'MyTable'
, tableQuery
, null
, function(error, result, response)
{
if (!error)
{
if (result.entries.length == 0)
{
var DataFound = "NO";
context.log("DataFound 1= " +DataFound);
context.log(result.entries.length );
}
else
{
var DataFound = "YES";
context.log("DataFound 2= " +DataFound);
}
}
else
{
var DataFound = "NO";
context.log("DataFound 3= " +DataFound);
context.log("Error retrieving entity:");
context.log(new Error(error));
context.log(response);
}
}
);
var oDataJson = JSON.stringify({DataExists: DataFound});
context.log(oDataJson)
return oDataJson;
}
now I know that the tableService.queryEntities
DataFound 2= YES
but I get an error at the line
var oDataJson = JSON.stringify({DataExists: DataFound}
);its complaingin that it cant find the value DataFound.
now I tried to define this variable outside of the tableService.queryEntities
so I need some help in making sure I can pass this value of YES or NO that is contained in "DataFound" to the calling function
ASKER
I tried that but it did not work,
What happens it just always defaults to NO
But looking at the log file I know
What happens it just always defaults to NO
But looking at the log file I know
ASKER
that the value is showing as DataFound 2="YES"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you may use Promise to let your code more readable :
if you need help, share more of you code (should OK with two functions at first look)
if you need help, share more of you code (should OK with two functions at first look)
like:
Open in new window