Optimize the code using assign?

can we write a if condition in assign activity rather than using if activity true and assign this value and flase assign the default value so that we can optimise the code ?

Yes we can achieve the same by using if or nested conditions in assign

can u just show a example ?

Hi @rob_lavelle

Yes you can write the If condition syntax in assign activity, check below expression,

- Assign -> Output = If(Condition, "True value", "False value")

Hope it helps!!

yes @rob_lavelle ,

refer below example for ref

  1. Create Variables:
  • inputValue (e.g., of type Int32)
  • result (e.g., of type String)
  1. Assign Activity:
Assign: result = If(inputValue > 10, "Greater than 10", "10 or less")

In this example, if inputValue is greater than 10, result will be assigned the string “Greater than 10”. Otherwise, it will be assigned “10 or less”.

Regards
Sandy

@rob_lavelle

result = condition ? valueIfTrue : valueIfFalse

can we also write nested conditions in this ?

For example… @rob_lavelle

- Assign -> Input = 60
- Assign -> Input = If(Input<50, 100, Input)

The condition is false Input value is not less than 50 then the Input variable again stores the same value.

Hope you understand!!

yes we can do ,

Assign: grade = If(score >= 90, “A”, If(score >= 80, “B”, If(score >= 70, “C”, If(score >= 60, “D”, “F”))))
Regards
Sandy

@rob_lavelle

If(condition1, If(condition2, valueIfBothTrue, valueIfCondition1TrueAndCondition2False), valueIfCondition1False)

This is the syntax

@rob_lavelle
at a particular level of nested if structures, we recommend focusing on alternates, due an increased readability and other factors.

But this depends on the details of the use case. Feel free to share more details along with sample data with us

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.