Learning PowerAutomate – Get Option set label

Let’s learn how to get option set label, without query to string map table for retrieving the labels.

As, we know that querying to an entity option set field will give us the option set value not the label. So if we want to get the option set label against any value

Note*: we can use an expression to get option set labels.

I have an option set attribute named as Loan type, which is present on Lead entity.
Querying on Lead entity, for attribute Loan type. I get the option set value not the label.

Therefore, to get the label against the retrieved value. I went using replace expression:

replace(replace(replace(string(triggerOutputs() ? ['body/new_loantype']), '43260000', 'HomeLoan'), '43260001', 'BusinessLoan'), '43260002', 'PersonalLoan')

The expression replaces the option set value with the given label.
Example, whenever we get the loan type as ‘43260000’, using the expression I will get the result as “HomeLoan”.

Moving ahead, we can use the set variable step under our flow. Where we can use the expression based on the output we receive for the above steps.

Additionally on top of the above requirement handling process, I went into another scenario where the option set field was coming null.
Reason, the field was marked as optional field. So, now its a user choice to enter data for option set field or leave it as null.

So, whenever I was getting the null value for the option set field records, I was getting an error as: Invalid type. Expected String but got Null.

Therefore for handling the null value exception, I went using empty expression:

if(empty(string(triggerOutputs()?['body/new_loantype'])),'',replace(replace(replace(replace(string(triggerOutputs() ? ['body/ new_loantype']), '43260000', 'HomeLoan'), '43260001', 'BusinessLoan'), '43260002', 'PersonalLoan')

The above expression helps us in handling null value. When we are passing loan type value to another variable of string type or to a child flow when the expected schema is of type “string”.

I hope this helps anyone! 😊