This article demonstrates how to use multiple If statements to build expressions in the Lasernet connector for Dynamics 365.
1. Go to the Report page by clicking Lasernet, and then clicking Reports under Common.
2. Locate the report to which you want to add an expression, and then click its record to open it.
3. On the left panel, you can see the report structure which is actually its XML structure. So, locate the section to which you want to add an expression, and then click it.
4. Afterwards, under the Fields section, click the New button. Within the new record that appears, specify a field name and output.
5. Click the sign with two pluses in the Expression field. As a result, the combo box shows. Select Expression in it.
6. Once the Expression value is added to the Expression field, click the sign with two pluses once again to set up the Expression. As a result, the Expression definition panel opens. Select the Plus sign button.
7. The Segment panel opens. There is a Value field and several Operators to choose from. For this example we will use an If statement for the expression. Select the If operator.
8. The expression now has several Operators and blank Values. Select the first blank value by clicking the button with the ellipses.
9. The Segment panel opens again. We will set up a condition for the If statement. Select the open parenthesis symbol.
10. Parentheses are now added to the expression. Select the first blank Value to begin building the condition.
11. Select the 2 pluses symbol on the Value field. This opens a dropdown. Select the table from the report that contains the desired field for validation.
12. Select the 2 pluses symbol again and select the field form the dropdown.
13. You now have the first argument of the condition. Select Ok on the Segment panel.
14. Select the Closed parenthesis symbol from the Expression definition to continue building the condition.
15. The Segment panel opens again. You now have more Operators to choose from. In this example, we will use the equals sign for our condition. Click on the equals Operator.
16. The expression has a new blank Value after the Operator we just added. Notice the expression reads, "If the field SalesInvoiceTmp.SalesPrice equals 'blank,' Then 'blank.'" Click on the blank Value after the equals Operator.
17. We will validate our Sales price against a specific value. On the Segment panel, click on the 2 pluses symbol on the Value field. Select Value.
18. Type in the Value in the Value field and select Ok.19. The Expression currently reads, "If SalesInvoiceTmp.SalesPrice is equal to 500.00, then 'blank,' else, 'blank'." If you have any extra blank values, click on it.
20. To get rid of unnecessary Expression fields, on the Segment panel, select Delete.
21. Now, we must determine what the field's value should be if the condition is met. Click on the blank Value after Then.
22. Click on the 2 pluses symbol on the Value field and select Value from the dropdown.
23. Type in the desired Value and click Ok.
24. The Expression now reads, "If SalesInvoiceTmp.SalesPrice is equal to 500.00, then 'Half a grand,' else, 'blank'." We can add a Value to the blank Value field after the Else field. The Value after the last Else in an expression is the default Value that will be used if none of the If conditions are met.
For this example, we will add another If statement first. Click on the blank value after the Else.
25. On the Segment panel, select If. This will build a nested If expression.
26. An expression can have multiple If statements. If the first If's condition is not met, the next If's condition is checked, if the next If's condition is also not met, the next If's condition is validated and so on. This will go on for as many If conditions as are in the expression until the final Else in the expression. If none of the If's conditions were met, the last Else's Value is used.
27. Build the next If's condition by selecting the blank value after the new If and repeating steps 8 through 24 with the following changes:
For step 15, use Operator Greater than instead of Equals.
For step 18, type in a Value of 1000.00 instead of 500.00.
For step 23, type in a Value of Over a Grand instead of Half a Grand.
28. Select the blank value after the last Else. We will make our Else value the same as the original field if none of the conditions were met. The Segment panel opens. Click the 2 pluses symbol and select the table.
29. Select the 2 pluses symbol again and select the field from the table. Click Ok.
30. The expression is now complete. It reads, "If the SalesInvoiceTmp.SalesPrice is equal to 500.00, then 'Half a grand,' Else, if SalesInvoiceTmp.SalesPrice is greater than 1000.00, then 'Over a grand.' Else use the SalesInvoiceTmp.SalesPrice."
31. Once the Expression definition status is "Expression is OK," click Ok.
32. Run the report with a Force rerun and check the XML for your newly added field.
The first If condition is met, Sales price is equal to 500.00 so the field's value is "Half a grand."
The second If condition is met, Sales price is greater than 1000.00 so the field's value is "Over a Grand."
None of the If conditions were met, Sales price is 350.00 so the field is just the Sales price.