Data Type References

In Appian, there are certain situations in which I need to check the data type of a rule input or local variable. While rule inputs have a defined data type, like Integer or Text, I can use the ANY-type in cases I need more flexibility.

Find a list of all data types here: https://docs.appian.com/suite/help/latest/Appian_Data_Types.html

Then, I can use the typeof() function to identify the data type of a value.

So, we have a value and can identify its type. How do I now compare that type in an if() or match() function?

Typeof() Function

I see many people using code like this:

if(
  typeof(ri!value) = typeof("Text"),
  <DO_THIS>,
  <DO_THAT>
)

While this is not wrong, I think this creates additional and unnecessary load on the system. Appian needs to create a text value, just to extract the type from the underlying metadata. And it can become misleading when I change that code to:

typeof(ri!value) = typeof("false")

Knowing that

false = "false"

evaluates to true, what does that above code do?

Let’s do better!

Type! Domain

Easy! Use the type!domain instead of the typeof() function!

In Appian, all data types can be directly references using the type! domain.

Our above code turns into this

typeof(ri!value) = type!Text

what makes it way more expressive and clear.

When saving the code, Appian turns the short

type!Text

into

'type!{http://www.appian.com/ae/types/2009}Text'

which is the full definition, including the namespace.

In the above code, I made a list of the most important data types. Check lines 7-9 where I created a list type reference, and a record type reference in line 10.

Summary

In my opinion, directly using record type references makes my code more expressive and easier to understand.

What is your opinion? Let me know in the comments.

Keep rocking your data types!

Leave a Reply