Showing posts with label Power Apps. Show all posts
Showing posts with label Power Apps. Show all posts

Saturday, 19 February 2022

Conditional formatting in Power Apps Gallery Control

Text Color:

I have label control that displays the Status of each issue, and the status is choice column in SharePoint list. Here I am trying to display different statuses in different colors.

Select Status label in the first row of the gallery, and at the top of the screen, select the Color property to type in the function box.

If the status is completed, show green, otherwise black.

If(
    ThisItem.Status.Value = "Completed",
    Color.Green,
    Color.Black
)

If you have multiple statuses wher you need to set up multiple colors: use Switch which is similar to IF.

In my scenario, if it’s completed show green, if In progress, purple, if Blocked, Red, otherwise if none of those are the case, the color will be black.

Switch(
    ThisItem.Status.Value,
    "Completed",
    Color.Green,
    "Blocked",
    Color.Red,
    "In Progress",
    Color.Purple,
    Color.Black
)


     When the record is selected:

If you want to fill the color for the selected record in gallery, please select the gallery control, and write the below function in TemplateFill property
If(
    ThisItem.IsSelected,
    ColorFade(
        RGBA(208,235,242,1
        ),
        -30%
    ),
    RGBA(0,0,0,0
    )
)



Bold Font:

If the task is assigned to the current user, the user’s name will be displayed in a bold font weight.

Click to select the label in the first row, that shows the “Assigned To” person’s name (It's a SharePoint People picker field). Select the FontWeight property.
If(
    ThisItem.'Assigned To'.Email = User().Email,
    FontWeight.Bold,
    FontWeight.Normal
)



Switch Icons:

If you would like to display a different icons for each of the 3 different priority levels. 

Select the first row of the gallery and Insert any icon from the Icons. There is a property called Icon on the icon, which tells you its name.

In my scenario, if the priority is High, show warning icon, if Medium, Information, if none of those are the case, Icon will be low/download.

Switch(
    ThisItem.Priority,
    "High",
    Icon.Warning,
    "Medium",
    Icon.Information,
    Icon.Download
)

Fill Color:

In Power App all the controls will have a Fill property, for the fill color. Here I want to show as a different color depending on the priority for a Icon. If it’s high priority, Red, if Medium, Orange, otherwise Aquamarine.

Switch(
    ThisItem.Priority,
    "High",
    Color.Red,
    "Medium",
    Color.Orange,
    Color.Aquamarine
)



Bow background Color:

If the status is equal to "In progress" show as Light yellow, otherwise white. To set the row’s background color, select the gallery, and go to the property called TemplateFill.

If(
    ThisItem.Status.Value = "In Progress",
    Color.LightYellow,
    Color.White
)



Disable a Icon or Button:

You can change the DisplayMode of any control, based on a condition. When you disable a button, by default it will show as grey, so that the button is still there, but clearly not clickable. In this example, I’ll use a Edit Icon, and I’ll disable it if the task has been completed. Select the Icon, go to the DisplayMode property:

If(
    ThisItem.Status.Value = "Completed",
    DisplayMode.Disabled,
    DisplayMode.Edit
)

Saturday, 5 February 2022

How to submit the data to multiple SharePoint lists in Power Apps

I have created below two SharePoint lists:

Customer Info: CustomerName(Title), CustomerID, ContactNumber, Country

Product Info: Title, Customer, CustID, Price

I have added Gallery and EditForm controls on the same screen and connected to 'CustomerInfo' SharePoint list as a data source.

Using the 'AddColumns' function I have added a new column to the result in Gallery control and I have set the result to new label control Refer my previous post here.

Fyi.. I am fetching the Price value from ProductInfo list.

In Button OnSelect property, SubmitForm(Form2_1) is updating the record in CustomerInfo list since it is the main source which is connected as data source. 

But I also need to update the Price value in ProductInfo list which is the main source of this field.

SubmitForm(Form2_1);
Patch(
    ProductInfo,
    If(
        FormMode = "New",
        Defaults('ProductInfo'),
        LookUp(
            ProdColll,
            CustID = DataCardValue2_1.Text
        )
    ),
    {Price: DataCardValue5_1.Text}
);

Here:

ProductInfo: Is the list where i wanted to update the Price field value.

Defaults(ProductInfo): This will create the new record if the formmode is New.

In Lookup: From the collection(ProdColll), I am comparing the CustID value and updating the datacard value in Price field.

Power Apps error: Invalid Formula. Expected a value compatible with 'DataSource'

My Gallery control and EditForm controls are connected to 'CustomerInfo' SharePoint list as data source.

I am trying to display the data on Form, based on my Gallery selection. To do this I have set this function on Form Item property: Gallery1.Selected which is throwing the error.

To fix this error, I have set the ID of the selected item in OnSelect property of Gallery:

Set(SelectedItemID, ThisItem.ID)

And In Form Item property, used Lookup function to retrieve the selected record from data source:

LookUp('CustomerInfo', ID=SelectedItemID)

How to display multiple SharePoint lists data in in Power App gallery

If you want to combine two SharePoint lists data and display the combined result within a gallery:

I have two SharePoint Lists: CustomerInfo and ProductInfo: In this scenario I will be comparing the Customer ID between two lists and getting the Price information on gallery.

I have created an app and added the Gallery control on the app:

Set the OnVisible property of your first screen of the app:
ClearCollect(
    CustColll,
    CustomerInfo
);
ClearCollect(
    ProdColll,
    ProductInfo
)


Set the Items property of the gallery control.:
AddColumns(
    CustColll, 
    "tempPriceValue",
    LookUp(
        ProdColll,
        CustID = CustomerID,
        Price
    )
)


Here: 
AddColumns: Function which will add the columns to table.
CustColl: Is the collection variable which I created above.
tempPriceValue: Above formula will add this column to result.

Finally, insert the label into gallery and update the Text property as below:
    ThisItem.tempPriceValue