Property Function - default value return Null

Certified Lead Developer

i am trying index the property "ISOCountryCodeOfIssue", if it is not available in the dictionary (data). We need to default value output.

We run the expression , it return back null instead of "BCD"

property(
{
/*ISOCountryCodeOfIssue: "ABC",*/
expiryDate: "10/20/2016",
issueDate: "10/20/2011",
documentId: "XR58",
documentType: "PASSPORT",
issuingAuthority: "EN"
}
,"ISOCountryCodeOfIssue","BCD")
Not sure what am i exactly missing here

  Discussion posts and replies are publicly visible

  • Strangely enough I can't say I've run into this "feature" with property() over a dictionary object..  I receive the same result of null vs "BCD" in my environment however.  Barring the unexpected functionality there, a few options are, use a!map() if you are on a recent version of Appian, or convert to a datasubset:

    property(
      a!map(
        /*ISOCountryCodeOfIssue: "ABC",*/
        expiryDate: "10/20/2016",
        issueDate: "10/20/2011",
        documentId: "XR58",
        documentType: "PASSPORT",
        issuingAuthority: "EN"
      ),
      "ISOCountryCodeOfIssue",
      "BCD"
    )

    property(
      todatasubset(
        {
          /*ISOCountryCodeOfIssue: "ABC",*/
          expiryDate: "10/20/2016",
          issueDate: "10/20/2011",
          documentId: "XR58",
          documentType: "PASSPORT",
          issuingAuthority: "EN"
        },
        a!pagingInfo(1,1)
      ),
      "ISOCountryCodeOfIssue",
      "BCD"
    )

  • 0
    Certified Lead Developer
    in reply to Chris

    Hate to say it, because it's such anathema to myself and Mike Schmidt, as we've had many discussions on the subject before, but if all else fails you could see how the index() function behaves getting your property.

    BTW, SUPER EXCITED to see someone on the forum actually starting with property() to get a property!  But if it has a failing, then I suppose I can extend more grace to all who use index() for everything.

  • SUPER EXCITED to see someone on the forum actually starting with property() to get a property!

    Amen!  Combined with INSERT -> CODE would have iced the cake :)

    Also to note, index() also provides the same NULL return, which is not what I would expect..

    index(
      {
        /*ISOCountryCodeOfIssue: "ABC",*/
        expiryDate: "10/20/2016",
        issueDate: "10/20/2011",
        documentId: "XR58",
        documentType: "PASSPORT",
        issuingAuthority: "EN"
      },
      "ISOCountryCodeOfIssue",
      "BCD"
    )

  • 0
    Certified Lead Developer
    in reply to Chris

    LOL, you guys read my mind.

    AFAIK property() and index() are aliases for the same back-end functionality so without testing I'd assume they'd both behave the same here.

    Without knowing the internal specifics, I suspect the issue here might relate to a funny aspect of Appian's handling of dictionary properties that I've noticed here and there... that is, when taking even a dot property directly into a dictionary, it won't fail if you try to grab a nonexistent property, but rather it'll return null.  I assume this means that property()/index() only return the "fallback" value if they try and FAIL to retrieve the property, but of course they don't fail, they just get null.

  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    Leave it to Appian to consider receipt of a "null" as something different than failing to acquire a value.  I can actually see that as a positive thing, because it normally is an assurance that the null really is there.

    local!tryData: property(data, "whatIWant", null)

    if (isnull(local!tryData), "Fall Back Text", local!tryData)

    That way if you get null from second or third parameter of property() you still wind up getting your fallback?

  • 0
    Certified Lead Developer
    in reply to Dave Lewis

    Issue here is that you then do not know whether the field does not exist or the value of the existing field is null. That could make a difference.

  • 0
    Certified Lead Developer
    in reply to Dave Lewis

    i tried something similar of this sort . but the in my case the i know the field name already . where sometimes , it will dynamic enough....

  • Unfortunately there is a bug with index/property that cannot be fixed due to our backwards compatibility guarantees. If you attempt to index into a field that does not exist on a dictionary, it will always return null instead of the defined default value.This should only apply to the dictionary data type, so consider using a!map() instead. This will be added to the documentation soon.