Skip to main content
dinesha5713
October 29, 2024
Question

Index vs property

  • October 29, 2024
  • 4 replies
  • 0 views

what is the main difference and what to use where

    4 replies

    venkatrea696188
    October 29, 2024

    Both are same , it clearly mentioned in Documentation that Property is alias of index

    Normal difference is ,We go for Property function when we try to get the value of a property/Field in CDT or dictionary like property(CDT,"field",default value) it can be achieved through index too

    And we use index to get the value from array like index(Array,3,null)

    mikes0011
    Brainy
    October 29, 2024

    Normal difference is ,We go for Property function when we try to get the value of a property/Field in CDT or dictionary like property(CDT,"field",default value) it can be achieved through index too

    And we use index to get the value from array like index(Array,3,null)

    Thank you, this is my normal soap box too.

    For code readability especially, i (100% of the time) recommend property() be used for getting a "field" from a CDT, and index() be used for getting the index i.e. position within an array, when it's not 100% clear whether the array will have an entry at that index.

    parthasarathym6661
    October 29, 2024

    Both functions are almost work in same way

    • property() ,property(cdt,"name",null) to try to get the name.
    • index(), index(array,2,null) to try to find the 2nd index of the array
    karumurua531442
    October 29, 2024

    Both functions do the same thing 

    When accessing properties in a CDT (Complex Data Type) or a Dictionary, use the `property()` function. For example, `property(ri!myCdt, "userId", null())` attempts to retrieve the "userId" dot property

    To look up an element in an array, use the `index()` function. For instance, `index(ri!myArray, 5, null())` tries to find the 5th item in the array. If the array does not contain that many elements, it will return null.

    It's crucial to clarify the purpose of function calls, especially when reading code. This way, it's much easier to understand if the "index()" call is trying to find a property or an array index. This distinction can become quite messy, particularly when functions are nested