Power Fx Snippets
Sources: 10 PowerFX Snippets to Boost Your Power Apps Development, GitHub - mathyousee/power-platform-snippets: A collection of snippets and samples related to the Power Platform
// Navigate in app and back using OnSelect propertyNavigate(Details)// Goes to Details screen// Got to Details with a screen transitionNavigate(Details, ScreenTransition.Fade)
// Go back to previous screenBack()
// Using OnVisible with a screen, make form editableFormMode.Edit
// Get application's display attributesApp.HeightApp.MinScreenHeightApp.Width
// Reference modern theme// https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/controls/modern-controls/modern-themingApp.Theme
// Manually style a classic control with current// modern themeButton.Fill = App.Theme.Colors.Primary
// If statement to control visibilityIf(Button.Pressed, true, false)
// Combine / Concatenate StringsConcatenate("Welcome, ", User().FullName, "!")
// If statement to set default item in dropdownIf(UserLocation = "CA", "Canada", "Select a Country")
// Date difference calculationDateDiff(Date1, Date2, Units)// Calculate a user's age in yearsDateDiff(BirthDate, Today(), Years)
// Sum dataSum(Table, Expression)
// Reset formSubmitForm(FeedbackForm); Reset(FeedbackForm)
// Get and set current logged in user informationSet(varCurrentUser, User());
Set( varCurrentUserID, LookUp( Users, 'Primary Email' = User().Email ));
// Filter data from https://learn.microsoft.com/en-us/power-platform/power-fx/reference/function-filter-lookup// Filter gallery dataFilter(Products, StartsWith(ProductName, SearchInput.Text))// Filter Items data where status is not equal to "Closed"Filter(Items, Status <> "Closed")// Filter data using searchSearch(IceCream, "choc", Flavor)
// Using OnVisible with a screen, make changes to components// Set data for use in componentsClearCollect( ButtonColorMapping, {Category: "WorkflowBtnColor", ButtonColor: RGBA(39, 67, 125, 1)}, {Category: "AiPortalBtnColor", ButtonColor: RGBA(0, 128, 128, 1)}, {Category: "DocMgmtBtnColor", ButtonColor: RGBA(4, 123, 193, 1)});
ClearCollect( ButtonData, { ID: 1, ButtonText: "Make Biscuits", Description: "Push paws up and down" }, { ID: 2, ButtonText: "Chase", Description: "Find mouse and follow" },);
// Set data depending on a condition// If current user is the owner of record and it is in WIP Stage, allow editing, else set forms to read onlySet( varIsEditMode, If( varCurrentItem.Owner = varCurrentUserID && varCurrentItem.Stage = 'Item'.WIP , true, false ));
// Notifications from https://www.powerplatformspace.com/snippets/read/8// Display success notificationNotify("Operation completed successfully!", NotificationType.Success);
// Display error notificationNotify("An error occurred while processing your request.", NotificationType.Error);
// Display warning notificationNotify("Warning: Please check your inputs.", NotificationType.Warning);
// Notification displayed for 3 secondsNotify("Your changes have been saved!", NotificationType.Success, 3000);
// Custom notification based on conditionIf( IsBlank(TextInput1.Text), Notify("Please fill out the required field.", NotificationType.Warning), Notify("Form submitted successfully!", NotificationType.Success));
// Display a welcome notification with the user's full name, using the "Information" notification type.Notify("Welcome back, " & User().FullName & "!", NotificationType.Information);
// User Defined Function, Supports Set, Collect, Reset, and Notify// https://learn.microsoft.com/en-us/power-platform/power-fx/reference/object-app#user-defined-functionsSpend( Amount: Number ) : Void = { If( Amount > Savings, Error( $"{Amount} is more than available savings" ), Set( Savings, Savings - Amount ); Set( Spent, Spent + Amount) );}