Skip to main content
July 3, 2024
Question

Index() function or Index by the dot in a variable (Example: local!user.name)

  • July 3, 2024
  • 8 replies
  • 0 views
Is there an advantage one over the other? In my current project, using the index with the dot is questioned as bad practice, requesting to always use the index() function, my question is, is this really necessary? what are the reasons? I understand that sometimes it is good to control the default value and set a null.

8 replies

July 4, 2024

Yes, it is bad practice. Simple example is, if you don't have value for the field and you use dot, then the index will fail, means it won't handle null propely except in value and saveinto parameters. But index() function will handle nulls and if there is no value for the field it returns null.

johibd1593
July 4, 2024

Yes It's not best practice If you have fixed value for any local variable you can use that variable with dot  but if you are defining local variable for any record or expression then you must use Index() function. 

konduruc733182
July 4, 2024

You can use both index() or property() functions. dot notations or the square brackets can be used for at your saveInto. But prefer index() if an array or property to get the properties. But it depends on your use case as well. Bottom line dot notation cannot handle null exceptions well and using property or the index() function will help you set a null exception.

mikes0011
Brainy
July 16, 2024
But prefer index() if an array or property to get the properties

my hero

stefanhelzle0001
July 4, 2024

There is one very important difference. index() or property() return a copy of the data while dot-notation or square-bracket-notation return a reference to the original data. Knowing this is crucial for using more complex data structures in saveInto where index()/property() will not work.

July 4, 2024

[mention:a11f77a729fb4db2af76b09948583328:e9ed411860ed4f2ba0265705b8793d05] Thanks for adding a closure note with a very important point.