Steve
05/31/2022, 5:44 PMvar findResponse = this.findOne( query={ "_id": "mid:#mid#[invalidkey]" } );
application.utilities.debug( module="daoI4goV5.getMerchant", text="Find #mid#", data=findResponse );
The debug line threw an exception because findResponse did not exist. Is this intentional and is there a best practice for handling this, meaning "try/catch", "isdefined()", "isnull()" (I'm not sure if the last even works, just throwing it out there)?Mark Takata (Adobe)
05/31/2022, 6:01 PMSteve
05/31/2022, 6:07 PMdfgrumpy
05/31/2022, 6:14 PMvar findResponse = [];
// do something
arrayIsEmpty(findResponse);
There are a bunch of ways to handle this. This example is just one.Steve
05/31/2022, 6:17 PMdfgrumpy
05/31/2022, 6:19 PMdfgrumpy
05/31/2022, 6:21 PMSteve
05/31/2022, 6:26 PMvar findResponse = {};
findResponse = this.findOne( query={ "_id": "mid:#mid#x" }, projection=projection );
application.utilities.debug( module="daoI4goV5.getMerchant", text="Find #mid#", data=isArray(findResponse)?findResponse:{} );
It keeps complaining that findResponse does not exist. Now I did find that isDefined("findReponse") does work, but the psyche thing.Steve
05/31/2022, 6:34 PMvar findResponse = this.findOne( query={ "_id": "mid:#mid#x" }, projection=projection );
application.utilities.debug( module="daoI4goV5.getMerchant", text="Find #mid#", data=isDefined("findResponse")?findResponse:{} );
return isDefined("findResponse")?findResponse:{};
If I insert an assignment on line 2:
findResponse = isDefined("findResponse")?findResponse:{};
And then simply reference findResponse, does the var scoping still apply, since it was reassigned to non existent?dfgrumpy
05/31/2022, 6:38 PMvar findResponse = {};
findResponse = this.findOne( query={ "_id": "mid:#mid#x" }, projection=projection );
result = structKeyExists(variables, 'findResponse') ? variables.findResponse : {};
application.utilities.debug( module="daoI4goV5.getMerchant", text="Find #mid#", data=result );
return result;
Steve
05/31/2022, 6:39 PMvar findResponse = this.findOne( query={ "_id": "mid:#mid#x" }, projection=projection );
var result = isDefined("findResponse")?findResponse:{};
application.utilities.debug( module="daoI4goV5.getMerchant", text="Find #mid#", data=result );
return result;
will work. It'll just be confusing for future maintenance. LOL - same solution.Steve
05/31/2022, 6:40 PMSteve
05/31/2022, 6:46 PMvar query = { "_id": "mid:#mid#" };
var findResponse = this.findOne( query=query );
// this structkeyexists() logic is required because at least with cf-2021, a findOne() returning "not found" wipes findResponse from existence
var result = structKeyExists(local, "findResponse") ? findResponse : {};
application.utilities.debug( module="daoI4goV5.getMerchant", text="Find #mid#", data={ query:query, result:result } );
return result;
(edit: The original "variables" scope did not work, changing to "local" scope did the trick)