Nested If

Coding in a dynamic manner is usually one of the best ways to construct a solution. In doing so, designers and programmers try to reduce the amount of guess work that the end user has to do in an effort to keep them productive the process streamlined. To make this magic happen, developers have to do the guess work programmatically. This requires them to get creative and inject varying forms of logic into the solution. The end user may enter data the same way every time, but the output may not be as straight forward as the entry.

In Power Apps, one of the forms of logic that we have available to us that allows us to lower the amount thinking the user has to do is the If() function https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-if. In short, the If() function checks to see if a condition is true then returns a result. The results of the evaluation can be a function that is nested inside of the If() or something as simple as a color or line of text.

Side note: The focus of this tutorial is the nested If() function. Additionally, the Switch() function will be featured as well. If I am being honest and I am, I didn’t want to write another section that spells out the switch function. The Microsoft Docs link that I provided about speaks about both functions.

The focus of the this blog will be nesting If() functions inside of another If() function. The scenario that we are programming for is moving an application from one environment to another. In order to move environments the application must have approval from the qualified individuals in the current environment. Our signoffs will be collected when a user checks a box. The checkbox visibility will be controlled by the selected items property in a dropdown control.

As always navigate to make.powerapps.com and what we want to do is create a canvas app it doesn’t matter which form factor you choose to utilize. For this exercise I will be using a mobile phone form factor.

Our first order of business is to add a dropdown control to our canvas.

In the items property enter the following

["","DEV","Test","UAT","All"]

Next we’re going to add a Switch() function into the OnChange property of the dropdown control. The purpose of this is to set a visibility variable based on the selected text in our dropdown.

Enter the following PowerFx expression into the OnChange property of the dropdown.

Switch(
Self.SelectedText.Value,
" ",
And(
UpdateContext({VarCheck1: false}),
UpdateContext({VarCheck2: false}),
UpdateContext({VarCheck3: false})
),
"DEV",
And(
UpdateContext({VarCheck1: true}),
UpdateContext({VarCheck2: false}),
UpdateContext({VarCheck3: false})
),
"Test",
And(
UpdateContext({VarCheck1: false}),
UpdateContext({VarCheck2: true}),
UpdateContext({VarCheck3: true})
),
"UAT",
And(
UpdateContext({VarCheck1: false}),
UpdateContext({VarCheck2: false}),
UpdateContext({VarCheck3: true})
),
"All",
And(
UpdateContext({VarCheck1: true}),
UpdateContext({VarCheck2: true}),
UpdateContext({VarCheck3: true})
)
)

Next we’re going to create our three checkboxes. The visibility of each checkbox will host one of the context variables that we created in the previous step.

For this instructional, the checkbox names will be generic. In the we will leverage two of the properties in our checkbox. The first being the default property. We want to use this property to set the default value of our checkbox to false if the checkbox is not visible. We will also use the visible property to toggle visibility on and off based on the selected item in the dropdown.

In the default property of the first checkbox or Checkbox 1 enter the following PowerFx expression If(VarCheck1 = false,false)

In the visible property of the first checkbox or Checkbox1 insert our context variable VarCheck1.

Using context variables VarCheck2 and VarCheck3, repeat the previous steps for Checkboxes 2 and 3.

Once we have our checkboxes wired up we can test the visibility of our checkboxes.

Now the moment that we’ve all been waiting for…..the Nested If().

If you have been following along and I hope that you have, the series of steps that we went through will all be brought together once we implement the Nested If(). Tying this altogether…If a checkbox is visible it must be checked in order for our submit button to become active. Removing a checkbox by changing the selection in the dropdown will clear it and only the remaining checkbox will need to be checked.

So…lets insert a button. We will leverage two properties here. The text property and the displaymode property.

In the text property of our button, enter in the following formula.

If(
If(
Checkbox1.Visible = true && Checkbox1.Value = true || If(
Checkbox1.Visible = false && Checkbox1.Value = false,
true
),
true
) && If(
Checkbox2.Visible = true && Checkbox2.Value = true || If(
Checkbox2.Visible = false && Checkbox2.Value = false,
true
),
true
) && If(
Checkbox3.Visible = true && Checkbox3.Value = true || If(
Checkbox3.Visible = false && Checkbox3.Value = false,
true
),
true
)

&& If(
And(
VarCheck1 = false,
VarCheck2 = false,
VarCheck3 = false
),
false,
true
),

"Ready to Move",
"Not Ready to Move"
)

At first glance this may not be easy to understand so I’ll break it down. Essentially, I have one If() function encasing multiple if functions, I then put another if function inside of that…still confusing. I know. So lets go with the basics.

The nested if works like this. We have a parent or top level If() function that houses the first If() function for Checkbox1 and it reads like this.

If(

If(Checkbox1 is visible(true) and Checkbox1 is checked (value = true) or

[another nested if]

If(

Checkbox1 is not visible(false) and Checkbox1 is not checked (value = false), then evaluate this If() to true

), If all conditions in this function are met, evaluate to true

)

If’s nested inside of another roll up to the parent, it is important that when you are designing your nested Ifs that you keep this in mind.

Finally we will leverage the display mode of the button. Paste the following into the displaymode property.

If(
If(
Checkbox1.Visible = true && Checkbox1.Value = true || If(
Checkbox1.Visible = false && Checkbox1.Value = false,
true
),
true
) && If(
Checkbox2.Visible = true && Checkbox2.Value = true || If(
Checkbox2.Visible = false && Checkbox2.Value = false,
true
),
true
) && If(
Checkbox3.Visible = true && Checkbox3.Value = true || If(
Checkbox3.Visible = false && Checkbox3.Value = false,
true
),
true
)

&& If(
And(
VarCheck1 = false,
VarCheck2 = false,
VarCheck3 = false
),
false,
true
),
DisplayMode.Edit,
DisplayMode.Disabled
)

And now for the final reveal..

I promise I’ll get better at these…Please leave feedback.

Custom Connector – ClickUp API

Foreword, foreword, foreword. A foreword written by the author. Ok…I like to share things that I’ve learned in practice for a client, things that I think are interesting concepts, and things that I think will extend the Power Platform. I like to extend the Power Platform to users that aren’t in the tenant, to provide users and clients with tools that they are familiar with…Insert custom connector, Power Apps Portal, webhooks, MS forms, emails…yada…yada…yada, this could’ve turned into the song that doesn’t end, and yes it does go on and on my friend….

Today, we will focus on the extensibility via the Custom Connector utilizing a tool that I like to use because it has a free tier that is more than useful — ClickUp. In short I use ClickUp the way that someone would use MS Planner, Monday.com, Jira, and the like. I’ve also worked with clients that use it as a ticketing system.

Because I work with the Power Platform, I thought that it would be neat to merge these two swell technologies.

First things first…you will need a ClickUp account, if you don’t have one visit https://www.clickup.com and get signed up or if you have a trusting friend ask to use theirs…

Lets begin…

First open notepad, a text editor, or have a paper and pencil handy. Honestly, I’d go with the copy and paste electronic method because the things that you are going to copy and paste will be pretty long…fine…nix the paper and pencil.

Now…

Once you’ve signed into your ClickUp Dashboard copy the team id from the address bar and paste it into notepad

Your team id will be after the first forward slash –indicated by the orange rectangle

Next go to settings and click on Integrations

Click on ClickUp API

Create App

Enter the name of your app and the redirect uri then select Create App. I use the standard redirect uri that we get back from Power Platform when we create a connector global.consent.azure-apim.net. It’s perfectly fine if you use it too. I promise I don’t own it…no rights whatsoever.

Once you successfully create your app, you will be provided with a Client ID and Client Secret, please copy and paste these to notepad as well.

Now the fun begins, it really doesn’t take long to go through the next steps…maybe. If you do this right, you will create a custom connector to ClickUp.

Documentation is your best friend, fortunately for us, ClickUp has documentation on how to work with their API. In a new tab/window navigate to https://clickup.com/api to see the docs and different actions that are at your disposal.

The first thing that we will need to do is generate a code for if you used the redirect uri that I provided in the previous step copy and paste the following address into your address bar, you will need to add your Client ID to the address

https://app.clickup.com/api?client_id={client_id}&redirect_uri=global.consent.azure-apim.net

After executing the previous step you will be prompted to connect to your workspace. If you’ve done everything right you will see the name of your app in the prompt. Select the workspace and click connect.

Once you select connect you will navigate to a new page. Please copy the code from the address bar and paste it into notepad.

Next we will generate our authorization code or API Key. You will need the Client ID, Client Secret, and the code from the previous step.

Return to https://clickup.com/api

  • Select Authentication
  • Get Access Token
  • Switch to Console
  • Insert
    • Client ID
    • Client Secret
    • Code
  • Call Resources
  • Scroll down to the response body and copy the authorization code then paste it to notepad

Next navigate to make.powerapps.com

  • Select Data
  • Select Custom Connectors
  • New Custom Connector
  • New From Blank
  • Name your connector
  • Click Continue

Next we will go through setting up general information for our connector. You can choose to upload an image for your connector or add a description – either not required. However, you will need to enter the host url and the base url.

The host url is api.clickup.com and in the base url input insert a forward slash /

Next we will set up the security for our connector and this is one of the easier steps.

The Authentication Type will be API Key, the value for Parameter Label and Parameter Name is “Authorization”, and the Location will be “Header”

Next we will create our connector definitions by navigating to the Definition tab.

Select New Action from the left pane.

In the General box the only required field is the operation id. I tend to name this something similar to whatever action is being performed.

Next we will want to select Import from sample in the Request box

For this tutorial, the action that we will be performing is getting all of the Workspaces in our team

Please select Get from the radio options.

Next enter the following url as is into the Url text input. We don’t want to hard code the team id into this we want to be able to access it from outside of the request by using curly brackets we create arguments that can be passed in from an app or flow.

https://api.clickup.com/api/v2/team/{team_id}/space

Finally select Import

Next select create connector to create the connector. Once the connector is created navigate to test here we will create our connection to the api.

Select New connection when prompted, enter the authorization code we created earlier, then create.

Once you click create you will be moved to the connections screen. if you’ve done it right you will see that you have a connection to the api.

Now lets go back to data>custom connectors > edit our newly created connector > test. In the GetSpaces box at the bottom of the page enter the team id into the text field and select test operation. If all goes well we will receive a 200 code and receive a JSON payload.

Copy the JSON payload and navigate to the Definition tab. In the response area select Add default response > paste payload into the body > import.

Finally update the connector. By adding this response we now have a schema for how our data is being returned and dynamic content to be used in our apps or flows once we import the custom connector into the process.

Now that we have the basic knowledge of how to create a custom connector for the ClickUp, feel free to see what other actions you can create. At the time of this publication I have 15 actions that I am using in an app. In the weeks to come I will share this with you.

Thanks for spending time with me. You could’ve been anywhere else on the world wide web, but you’re here with me…I appreciate that.

How Did We Get Here?

The first thing that I want to get across to whoever reads this is…YOU CAN DO IT. If you’re reading this, you may have just embarked on your journey with the Power Platform, you’re organization is thinking about making the switch to go Low-Code, or you’re like me and knee deep in Power Platform, but routinely look up to marvel at where you are.

I’m Duke by the way…I have been working with the Power Platform for two years and have apps and flows in every time zone in the continental United States, hopefully I can get to Alaska and Hawaii, then the rest of the world.

How did we get here? My path to the Power Platform, may seem similar to yours or completely devoid of the nuisances and challenges that you’ve faced. However, we’re here.

I started working in a factory at age 25 while attending school full time, simultaneously. Prior to graduation, I accepted an analyst position in the IT department. For about 7 months I worked as a help desk technician assisting users with issues related to our ERP system. Although, I was grateful for this opportunity, I needed to find my spot and ultimately something that I owned. Each member of the team had their niche and they did well at it.

In the middle of all of this, the guy that took a chance on me and hired me left the company and I felt like I was in limbo. For about two months I did my job wondering what the next phase would be. I knew that new leadership would bring new challenges and who knows, maybe I’d lose my job. Fortunately, things turned out well and I was introduced to SharePoint.

I know, you probably thought that I would say I dove right into the Power Platform, but trust me its happened this way for a lot of people. SharePoint….I can’t say I was too happy about my new role as a part time SharePoint admin, but it was new for me and I had something that I could own. I thought it would be temporary as I was tasked with moving our current company intranet over to SharePoint online, but it blossomed.

The finance team was looking to replace their matrix approval flows. I knew nothing about flows in general (remember factory worker, now IT). Initially we were going to build them using the 2013 workflows in SharePoint, but they weren’t as robust as the CFO needed them to be. We needed a way to resolve this matter and I didn’t want to let my boss down as he was new to the company.

Playing around in a SharePoint list one day, I noticed that there was a button at the very top. The “Flow” button.

What was this “Flow” thing and why was it? Little did I know, it was at this moment that I “discovered” the Power Platform.

To meet the requirements of the finance department, the flow would need to follow our authority matrix for approvals which was manageable because flow has approval functionality, but the fun didn’t stop there, they wanted a dashboard.

There is one small problem with approvals in flow. In order to interact with the request, users would have to use Outlook, for our operation this wasn’t feasible and I wouldn’t recommend it for high volume requests.

Suffice it to say, I was stuck and our solution was incomplete, I’ve only been at this for about 3 months and there seemed like no way up. We needed this dashboard to complete our solution or we were dead in the water. After googling multiple combinations of “dashboard with flow”, “dashboard with SharePoint”, and the like, I once again made another “discovery”, Power Apps.

One week before I was to deliver the finished product, I scrapped all of my work and took a different approach using flow to move the requests once a determination was made in the custom dashboard in Power Apps. I watched tons of videos and practically slept in my basement to make sure we could deliver the solution on time.

During the duration of the project I discovered that I had an affinity for the Power Platform, so much so that I purchased my own tenant so I could make and break things. I began freelancing in addition to my day job and started networking to meet other #PowerAddicts.

Eventually, I left my position at my former employer to become a consultant at Hitachi Solutions of America because I wanted to do all things Power Platform – all day and I’m still learning and growing.

I wanted my first post to be a solution or a tutorial, but I wanted to let you know how we got here. The use of we is intentional. If there is anything that I learned while working on the Power Platform is that it is a community and you should leverage it. Commonality is an overarching theme in Microsoft’s Power Platform community, we may have different use cases and work in different industries, but believe it or not we are all solving problems to aid our businesses in streamlining their processes. I have seen so many different solutions created by the community and I often take bits and pieces and add them to my solutions. Now I’m at the point where I need to pay it forward and share.

We are accountants, former engineers. We are pro developers and citizen developers. The good thing about this platform is that there is a space for everyone, its inclusive. I urge you to follow some of the superstars in the community and if you feel so inclined subscribe and follow me.

We’re going to have fun…