Dynamic search for custom object property
If I convert JSON to a custom object, I can access the custom object's properties only if I explicitly call them. e.g. When I iterate through the elements of custom object, I need to specify %CurrentItem.propertyname%. However, if the property names are set in a list and I try to use %CurrentItem.list%, WA throws an error, "List is not a valid field". It will be nice to have this feature of accessing the custom object's property values dynamically, with WA just throwing this error if a illegal name was indeed passed.
While using another variable to iterate properties of a custom object or of any other variable is not possible (neither through index or name), please note that in case of custom object you can create a work around if you convert it to json.
In this case all the properties and their value because a text value and they can be parsed and create a new list which you can now iterate using the index. In case each property includes one value this is a simple task (see attached), but in case properties include lists or more complex objects then obviously it is not that simple as you cannot create a list with different type of variables.
Thanks for the clarification Sumit.
I understand that you would like the property of a Custom Object to be a variable.
However, as you already know, if a variable is inside another variable, we do not need the internal "%" signs.
So, if we write %CurrentItem.NewVar% there is no way for WinAutomation to understand if "NewVar" is a variable or a value.
Does it make sense?
Thanks Peter for responding. That part does work, but I was referring to dynamic variable name at run time. In your example, it will work if I say %CurrentItem.Name%. However, let's say I want to access the values of Surname and Department and I have a list [List] with these two keys.So
List = Surname
List = Department
Now if I try to access it with %CurrentItem.List%, it will not work. It will only work if I specify %CurrentItem.Surname%. We have a requirement where the key-value pair in the JSON are constantly changing. So we wanted to specify the "keys" we want to access in a comma separated txt file so that we can read these at run time into a list and then access it using %CurrentItem.List%.
Please note that in case the property of a Custom Object is of type "list", then you should be able to access the list items like you mention.
For example, please try to convert the following JSON text to a custom object, using the "Convert Json to Custom Object" Action.
You will notice that the Names can be accessed by their indexes.