Hi,
I am wondering if there is a way to check whether the value stored in a local variable is a record type instance, so that I can use the a!keys() function to retrieve the list of fields and then index through it. Unfortunately, the code below returns a unique UUID for the record instead of something generic like "Record Type" that I could check against using a simple if condition.
typename( typeof( ABC Comment( id: 1, comment: "test" ) ) )
Also, if anyone knows an even better solution to check not only for record types but for any type that can be accepted by the a!keys function (e.g. record type, map, dictionary etc), that would be great. Thank you!
Discussion posts and replies are publicly visible
Could you try thisMake sure localVariable would be single type(Not list.)
if( isnull(a!keys(local!yourVariable)), "not a valid type", "is record/map/CDT/dictionary" )
Hi Shubham, thank you for sharing your idea. The issue I'm facing is that in my case local!yourVariable can be any value, including primitives like Integer or Text, that will basically make a!keys() to return an error.
local!yourVariable
a!keys()
Try this but not recommended for production.
try( if( isnull(a!keys(local!yourVariable)), "not a valid type", "is record/map/CDT/dictionary" ), if( find("error", fn!lastError().details), "not a valid type", {} ) )
Thanks. I actually considered using try() as a final solution for exception handling, but I'd prefer to avoid doing so since it's not a documented function and is not recommended for use.
I do not know of a good way to identify such types. try() is no way.
But, maybe the issue lies deeper. What actual problem to you try to solve?