difference between Property & index function?

What is the key difference between the property() & index() function?Can anybody tell?

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Both functions do the same thing in the same way, as is (vaguely) noted in the documentation.

    However, I strongly recommend as a Best Practice, to use them separately, as follows:

    • property() when looking up i.e. a dot property of a CDT or Dictionary, as in property(ri!myCdt, "userId", null()) to try to get the "userId" dot property
    • index() when looking up an array index, as in index(ri!myArray, 5, null()) to try to find the 5th member of the array, and if the array isn't that long, return null.

    This is most important to me since it makes it dramatically easier to read through code afterwards if you're not having to guess whether this "index()" call is trying to find a property or an array index, which can get pretty messy especially when the functions are nested.

Reply
  • +1
    Certified Lead Developer

    Both functions do the same thing in the same way, as is (vaguely) noted in the documentation.

    However, I strongly recommend as a Best Practice, to use them separately, as follows:

    • property() when looking up i.e. a dot property of a CDT or Dictionary, as in property(ri!myCdt, "userId", null()) to try to get the "userId" dot property
    • index() when looking up an array index, as in index(ri!myArray, 5, null()) to try to find the 5th member of the array, and if the array isn't that long, return null.

    This is most important to me since it makes it dramatically easier to read through code afterwards if you're not having to guess whether this "index()" call is trying to find a property or an array index, which can get pretty messy especially when the functions are nested.

Children