0% found this document useful (0 votes)
13 views13 pages

Evaluate Nested Logic Exercise

This document provides a tutorial on using nested if() and a!match() functions in Appian to return mapped values based on input conditions. It includes setup instructions for two practice exercises, tips for performance evaluation, and additional resources for learning. The document emphasizes the importance of naming conventions, saving work frequently, and utilizing community resources for practice.

Uploaded by

inspire04172024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views13 pages

Evaluate Nested Logic Exercise

This document provides a tutorial on using nested if() and a!match() functions in Appian to return mapped values based on input conditions. It includes setup instructions for two practice exercises, tips for performance evaluation, and additional resources for learning. The document emphasizes the importance of naming conventions, saving work frequently, and utilizing community resources for practice.

Uploaded by

inspire04172024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Evaluate Nested Logic Exercise

Advanced Expressions

Introduction 2
How to Complete the Exercises in this Tutorial 2
How Can I Practice? 2
Appian Version 2
Naming Conventions 2
Save Often 3
Additional Resources 3
Practice 1 Set Up: Use Nested if() Functions to Return Mapped Values 4
Practice 2 Set Up: Use the a!match() Functions to Return Mapped Values 7
Practice 1 Help and Resources: Use Nested if() Functions to Return Mapped Values 10
Additional Resources 11
Practice 2 Help and Resources: Use the a!match() Functions to Return Mapped Values 11
Additional Resources 13

Notice of Rights

This document was created by Appian Corporation, 7950 Jones Branch Dr, Tysons, Virginia 22102.
Copyright 2024 by Appian Corporation. All rights reserved. Information in this document is subject to
change. No part of this document may be reproduced or transmitted in any form by any means, without
prior written permission of Appian Corporation. For more information on obtaining permission for
reprints or excerpts, contact Appian Training at [email protected].

© Appian Corporation, 2024


Introduction
How to Complete the Exercises in this Tutorial
Follow the steps to complete practice 1 and 2.

How Can I Practice?


You should practice in Appian Community Edition. This free, community Appian resource
comes with the pre-built Acme Auto application that contains objects that you’ll use to build
your expression rules.

Keep in mind that this is a community environment not suitable for production workloads or
sensitive information.

Appian Version
Appian Community Edition is on the latest Appian version. If you are following the exercises
from a previous Appian version, go to academy.appian.com to download the latest version.

Naming Conventions
When you register for Appian Community Edition, you gain access to a workspace, which is
your personal area within the community environment. When your workspace has been
assigned, you will receive a confirmation email with a workspace ID.

Use this workspace ID when creating new applications and objects. Otherwise, you could run
into naming conflicts with objects created by other users. Pre-loaded apps in your workspace
also include the workspace ID. In the example below, the application prefix for the Acme
Auto Solution app is W0000AS. So, the workspace identifier is W0000, which would be
included in any new app’s prefix.

24.3

© Appian Corporation, 2024 2


Save Often
Appian does not automatically save updates, so save your objects frequently.

Additional Resources
Appian provides a number of training resources for Appian developers. The following
resources are particularly popular with our learners:

● Academy Online - Appian’s online courses provide useful survey courses, step-by-step
tutorials, and practice exercises. Explore these resources at your own pace. Survey
courses will help you develop a better grasp of the topics you need to learn. Video
and print tutorials will help you with getting hands-on experience with Appian.

● Community Discussions for New Users - Check out the New to Appian thread in
Community. Join our community of experts to ask questions and find answers from
past discussions.

● Appian Documentation - Appian’s product documentation will provide you with an


overview of key Appian features, newest release information, additional tutorials,
and helpful patterns and recipes to implement in your app.

24.3

© Appian Corporation, 2024 3


Practice 1 Set Up: Use Nested if() Functions to Return
Mapped Values
You learned that Arrays in Appian are classified as specific data types. You also learned that
it’s best to convert some data types before using Appian functions on the data, to avoid
problems that occur when a function is looking for a specific data structure, such as a List of
Text String or List of Number.

In this lesson you’ll use the expression editor to create some data arrays, view their data
structures, and determine whether or not you should convert them.

1. In Appian Designer, create a new expression rule.

● Name: Enter W#AE_NestedIf

● Description: Enter Practice nesting if functions.

2. Create a Number (Integer) rule input and name it: typeId

3. Copy and paste the following expression:

/*

The rule testing conditions

ID Name Icon

-- ---- ----

1 "Purchase Order" "money" a!map(name:


"Purchase Order", icon: "money")

2 "Contract" "file-pdf-o" a!map(name:


"Contract", icon: "file-pdf-o")

3 "Invoice" "paper-plane-o" a!map(name:


"Invoice", icon: "paper-plane-o")

4 "Negotiation" "Review file-pdf-o" a!map(name:


"Negotiation", icon: "Review file-pdf-o")

5 "Service" "cogs" a!map(name:


"Service", icon: "cogs")

24.3

© Appian Corporation, 2024 4


other "Error" "error" a!map(name:
"Error", icon: "error")

*/

If(

ri!typeId=1, a!map(name: "Purchase Order", icon: "money"),

If(

ri!typeId=2, a!map(name: "Contract", icon: "file-pdf-o"),

a!map(name: "Error", icon: "error")

Help

For a given rule input, the expression returns the name and icon associated with
the document type. The nested if() functions are configured to return the proper
map for the name: and icon: value pairs, according to the following mapping.

Input Value Returned Expression

1 a!map(name: "Purchase Order", icon: "money")

2 a!map(name: "Contract", icon: "file-pdf-o")

any other integer a!map(name: "Error", icon: "error")

4. In the Test Inputs Expression, enter: 1

● The Test Output should be of type Map. The value should be:

i. Name: "Purchase Order" (Text)


24.3

© Appian Corporation, 2024 5


ii. Icon: "money" (Text)

5. Continue testing with values 2 through 6 as your input value for the Expression. You’ll
notice that any value above 2 returns an error value for both name and icon.

6. Complete the expression rule, such that it returns a map value pair for the other input
values listed in the following table.

Input Value Returned Expression

1 a!map(name: "Purchase Order", icon: "money")

2 a!map(name: "Contract", icon: "file-pdf-o")

3 a!map(name: "Invoice", icon: "paper-plane-o")

4 a!map(name: "Negotiation", icon: "Review file-pdf-o")

5 a!map(name: "Service", icon: "cogs")

any other integer a!map(name: "Error", icon: "error")

Tip

Add three more nested if() functions to handle conditions where the input value
is 3, 4,or 5.

7. Test input values 1-6 and confirm the test output values match the table above.

8. To better understand why nested If() functions are not performant, enter: 5 as your
input value and click Test Rule.

9. Under the Test Output line, click View Performance.

10. Scroll down to view Descendent Functions. Notice that the expression evaluates five
consecutive nested if() functions before reaching a conclusion about the value it
returns.

The first if() function evaluates a single condition: ri!typeId=1. If this condition
evaluates to true, the first parameter, which is defined as a!map(name: "Purchase
Order", icon: "money") is returned, and the rest of the parameters are not evaluated.

If the condition evaluates to false, the second parameter, which itself is another if()
function, needs to be evaluated. This continues until the last condition is evaluated.

24.3

© Appian Corporation, 2024 6


Nesting if() functions to handle multiple conditions is non-performant and difficult to
maintain. In the next exercise, you’ll explore using an alternative method for handling
multiple conditions.

Practice 2 Set Up: Use the a!match() Functions to


Return Mapped Values
In this lesson you’ll use the expression editor to create some data arrays, view their data
structures, and determine whether or not you should convert them.

1. In Appian Designer, create a new expression rule.

● Name: Enter W#AE_Match

● Description: Enter Practice applying the match function.

2. Create a Number (Integer) rule input and name it: typeId

3. Copy and paste the following expression:

/*

The rule testing conditions

ID Name Icon

-- ---- ----

1 "Purchase Order" "money" a!map(name:


"Purchase Order", icon: "money")

2 "Contract" "file-pdf-o" a!map(name:


"Contract", icon: "file-pdf-o")

3 "Invoice" "paper-plane-o" a!map(name:


"Invoice", icon: "paper-plane-o")

4 "Negotiation" "Review file-pdf-o" a!map(name:


"Negotiation", icon: "Review file-pdf-o")

5 "Service" "cogs" a!map(name:


"Service", icon: "cogs")

other "Error" "error" a!map(name:


"Error", icon: "error")

24.3

© Appian Corporation, 2024 7


*/

a!match(

value: ri!typeId,

whenTrue: ri!typeId=1,

then: a!map(name:"Purchase Order", icon: "money"),

whenTrue: ri!typeId=2,

then: a!map(name:"Contract", icon: "file-pdf-o"),

default: a!map(name:"Error", icon: "error")

Help

For a given rule input, the expression returns the name and icon associated with
a document type ID. The a!match() function is configured to return the proper
map for the name: and icon: value pairs according to the following mapping.

Input Value Returned Expression

1 a!map(name: "Purchase Order", icon: "money")

2 a!map(name: "Contract", icon: "file-pdf-o")

any other integer a!map(name: "Error", icon: "error")

4. In the Test Inputs Expression, enter: 1

● The Test Output should be of type Map. The value should be:

i. Name: "Purchase Order" (Text)

ii. Icon: "money" (Text)

24.3

© Appian Corporation, 2024 8


5. Continue testing with values 2 through 6 as your input value for the Expression. You’ll
notice that any value above 2 returns an error value for both name and icon.

6. Complete the expression rule, such that it returns a map value pair for the other input
values listed in the following table.

Input Value Returned Expression

1 a!map(name: "Purchase Order", icon: "money")

2 a!map(name: "Contract", icon: "file-pdf-o")

3 a!map(name: "Invoice", icon: "paper-plane-o")

4 a!map(name: "Negotiation", icon: "Review file-pdf-o")

5 a!map(name: "Service", icon: "cogs")

any other integer a!map(name: "Error", icon: "error")

7. Test input values 1-6 and confirm the test output values match the table above.

8. To better understand why the a!match() function is more performant than nested if()
functions, enter: 5 as your input value and click Test Rule.

9. Under the Test Output line, click View Performance.

Tip

Unlike most functions, a!match() does not always evaluate all of its
parameters.The function will only evaluate equals and whenTrue parameters until
it finds a match to the value parameter. After it finds a match, the following then
parameter will be evaluated and any remaining parameters will be ignored.

Use the a!match() function to avoid calling potentially costly expressions.

24.3

© Appian Corporation, 2024 9


Practice 1 Help and Resources: Use Nested if()
Functions to Return Mapped Values
Review what your expression should look like. Also, check out the listed resources to learn
more about indexing values in an array.

1. Add an if() function to return a!map(name: "Purchase Order", icon: "money")


2. Add a comma followed by the next if() function until all 6 values are accounted for
3. In the last if(), be sure to update the valueIfFalse parameter with the error values

4. In Test Output, click the View Performance link.


5. The Descendant Functions and Query Rules table shows the fn!if function and its count

24.3

© Appian Corporation, 2024


10
Additional Resources
● if() function

Practice 2 Help and Resources: Use the a!match()


Functions to Return Mapped Values
Review what your expression should look like. Also, check out the listed resources to learn
more about indexing values in an array.

1.
Add the match() function
For the value parameter, enter: ri!typeId
2.
3.
For the first whenTrue parameter, enter: ri!typeId=1
4.
For the first then parameter, enter: a!map(name: "Purchase Order", icon:
"money)
5. Add additional whenTrue and then parameters for input ids 2-5.
24.3

© Appian Corporation, 2024


11
6. For the default parameter, enter: a!map(name: "Error", icon: "error")

7. In Test Output, click the View Performance link.


8. The Descendant Functions and Query Rules table shows the a!match function and its
count

24.3

© Appian Corporation, 2024


12
Additional Resources
● a!match()

24.3

© Appian Corporation, 2024


13

You might also like