Search This Blog

Thursday, December 31, 2020

Modify or create a record (in a data source)/Merge records (outside of a data source)

You'll modify or create a record in a data source, named IceCream, that contains the data in this table and automatically generates the values in the ID column:

Example icecream

MODIFY OR CREATE A RECORD (IN A DATA SOURCE)
FormulaDescriptionResult
Patch( IceCream,
Lookup( IceCream, Flavor = "Chocolate" ), { Quantity: 400 } )
Modifies a record in the IceCream data source:
  • The ID column of the record to modify contains the value of 1. (The Chocolate record has that ID.)
  • The value in the Quantity column changes to 400.
{ ID: 1, Flavor: "Chocolate", Quantity: 400 }

The Chocolate entry in the IceCream data source has been modified.
Patch( IceCream, Defaults( IceCream ), { Flavor: "Strawberry" } )Creates a record in the IceCream data source:
  • The ID column contains the value 3, which the data source generates automatically.
  • The Quantity column contains 0, which is the default value for that column in the IceCream data source, as the Defaults function specifies.
  • The Flavor column contains the value of Strawberry.
{ ID: 3, Flavor: "Strawberry", Quantity: 0 }

The Strawberry entry in the IceCream data source has been created.

After the previous formulas have been evaluated, the data source ends with these values:

Example icecream after

Merge records (outside of a data source)

MERGE RECORDS (OUTSIDE OF A DATA SOURCE)
FormulaDescriptionResult
Patch( { Name: "James", Score: 90 }, { Name: "Jim", Passed: true } )Merges two records outside of a data source:
  • The values in the Name column of each record don't match. The result contains the value (Jim) in the record that's closer to the end of the argument list instead of the value (James) in the record that's closer to the start.
  • The first record contains a column (Score) that doesn't exist in the second record. The result contains that column with its value (90).
  • The second record contains a column (Passed) that doesn't exist in the first record. The result contains that column with its value (true).
{ Name: "Jim", Score: 90, Passed: true }

Use of As or ThisRecord

Using the As or ThisRecord keyword in the formula avoids ambiguous evaluation context.

In the example below, consider the first lookup in the If statement. (OrderID = A[@OrderID]) is expected to compare the OrderId in the lookup scope with the OrderId of collection A in the ForAll scope. In this case, you likely want A[@OrderId] to be resolved as a local parameter. But it is ambiguous.

Power Apps currently interprets both the left-hand side OrderId and right-hand side A[@OrderId] as a field in the lookup scope. Therefore, lookup will always find the first row in [dbo].[Orders1] because the condition is always true (that is, any row's OrderId is equal to itself.)

ClearCollect(
    A,
    Filter(
        '[dbo].[Orders1]',
        OrderId = 8888888
    )
);
ForAll(
    A,
    If(
        LookUp(
            '[dbo].[Orders1]',
            OrderId = A[@OrderId],
            "OK"
        ) = "OK",
        Patch(
            '[dbo].[Orders1]',
            LookUp(
                '[dbo].[Orders1]',
                OrderId = A[@OrderId]
            ),
            {
		OrderName: "val1"
	    }
	),
	Patch(
            '[dbo].[Orders1]',
            Defaults('[dbo].[Orders1]'),
            {
		OrderName: "val2"
	    }
	)
    )
)

Using As or ThisRecord

Whenever possible use the As operator or the ThisRecord to disambiguate the left-hand side. As is recommended for the above scenario.

When your formula uses multiple scopes with ForAllFilter, and Lookup on the same data source or table, it is possible that the scope parameters may collide with a same field elsewhere. Therefore, it is recommended to use the As operator or ThisRecord to resolve the field name and avoid ambiguity.

For example, you can use the As operator to disambiguate in the example below.

ClearCollect(
    A,
    Filter(
        '[dbo].[Orders1]',
        OrderId = 8888888
    )
);
ForAll(
    A,
    If(
        LookUp(
            '[dbo].[Orders1]' As B,
            B.OrderId = A[@OrderId],
            "OK"
        ) = "OK",
        Patch(
            '[dbo].[Orders1]',
            LookUp(
                '[dbo].[Orders1]' As C,
                C.OrderId = A[@OrderId]
            ),
            {
		OrderName: "val1"
	    }
	),
	Patch(
            '[dbo].[Orders1]',
            Defaults('[dbo].[Orders1]'),
            {
		OrderName: "val2"
	    }
	)
    )
)

Alternatively, you can use ThisRecord for the same purpose.

Power Apps
ClearCollect(
    A,
    Filter(
        '[dbo].[Orders1]',
        OrderId = 8888888
    )
);
ForAll(
    A,
    If(
        LookUp(
            '[dbo].[Orders1]',
            ThisRecord.OrderId = A[@OrderId],
            "OK"
        ) = "OK",
        Patch(
            '[dbo].[Orders1]',
            LookUp(
                '[dbo].[Orders1]',
                ThisRecord.OrderId = A[@OrderId]
            ),
            {
		OrderName: "val1"
	    }
	),
	Patch(
            '[dbo].[Orders1]',
            Defaults('[dbo].[Orders1]'),
            {
		OrderName: "val2"
	    }
	)
    )
)

Update Sharepoint list items when click on Submit in Powerapps (Survey App)

 Hi All,

Need a help in updating the sharepoint list when I click submit in Survey App created in PowerApps

I created a SP list and from there I created an app using the SP list in PowerApps

Requirement as below.

  1. The survey is supposed to be sent to new joinees after they complete 30 days in the company via an automated email.
  2. Before doing so, I should have a working App, so I created multiple edit forms in Power Apps (screenshots below). However, I failed in achieving the same. Any help is appreciated on this

Need help with the below:

  1. I created a landing page where the employee has to input his EMP ID, he cannot go to next page until employee enter his/her employee id. However, I want to display a message saying "please enter your emp id" when he/she clicks on Start.
  2. In Question1 form, I want the employee to select one option. Want to display a message that "atleast one option should be selected" if they click on next without selecting any option
  3. In Question2 form, when the employee click submit I want those results to be updated in the sharepoint list where I have some details against their employee id. I do not want to create a new item for the survey results in the list. However using Patch () Defaults() i see that two more items were created and the items updated only the questions in the survey but no other details were captured including Employee ID

Below are the screen shots of the list and the app

LandingScrren_Survey.JPGScreenshot1_Survey.JPGScreenshot2_Survey.JPGSP_List_Survey.JPG


Wednesday, December 30, 2020

Model Driven vs. Canvas Power App App Major Differences

 

eaturesCustomized list form [Model-Driven Apps]Standalone app [Canvas Apps]
Permissions/Share OptionsSharePoint permissions on the listUser or Co-owner
TemplatesDefault Modern List Template only available which can be further customizedFew dozen pre-built canvas app templates available
End-user interactionOn the listfrom the list of PowerApps, or using a direct link
MobileIn the SharePoint app, if embedded as a web partIn the PowerApps app
DesigningFrom the list, customize list format web.powerapps.com
ExportCan’t be doneat web.powerapps.com
Versioningsave, then see all versionsfrom the app’s details screen, web.powerapps.com
Data FocusFocused on dataFocused on the user interface
StructureInput data to define structural componentsDrag and drop components onto a blank canvas
Data SourcesPulls data from Common Data Service(CDS)Can pull data from over 200 data integration sources out of the box
ResponsivenessResponsive by designNot responsive by design
Business NeedsBest suited for creating end-to-end solutionsBest suited for task-based or role-based applications

Friday, December 25, 2020

A piece of Code Add, edit,save ,cancel,reload.

 Hi  All find code of Add, edit,save ,cancel,reload in powerapp,

Icon

Code Logic

Add New

UpdateContext({NewDisplayMode: DisplayMode.Edit}); UpdateContext({EditDisplayMode: DisplayMode.Disabled})

Edit

UpdateContext({NewDisplayMode: DisplayMode.Disabled}); UpdateContext({EditDisplayMode: DisplayMode.Edit})

Cancel

UpdateContext({NewDisplayMode: DisplayMode.Disabled}); UpdateContext({EditDisplayMode: DisplayMode.Disabled})

Save

If (NewDisplayMode = DisplayMode.Edit,

    If (!IsBlank(LastNameField) && !IsBlank(EmailAddressField),

        SubmitForm(AddNewForm); ResetForm(AddNewForm); Refresh(Contacts),

        Notify("Cannot create record. Missing data.", NotificationType.Error)),

    true);

UpdateContext({NewDisplayMode: DisplayMode.Disabled}); UpdateContext({EditDisplayMode: DisplayMode.Disabled})

Reload

Refresh(Contacts)


Create a simple quiz app/survey app in PowerApps.

 Home Screen

 
In this screen, we will add a label (for the quiz) and button (to start the quiz) as below,
 
Home Screen
 
On the selection of the button, we will navigate to the question 1 screen. So we will write the formula on the OnSelect property as below,
  1. Navigate(Question1)  
Now we will add some controls for the all questions screens like labels for question number and question, the radio button for the options and button for the check answer, and store in some variable and move to the next screen. So let's see the implementation.
 

Question 1 Screen

 
The output screen will be like this, 
 
QUestion2
 
We will write a formula on the OnSelect property of the Next button. Now we will set the score as if the answer is wrong then 0 and if right then 5 and then navigate to the Question2 screen. 
  • We will use if condition and in if condition we will get radio button selected value and will check with our answer and will set score = 5 if the answer is true; else will set to 0.
  • then we will reset the radio button selected value
  • and then will navigate to the next screen. 
  1. If(  
  2.     Radio1.Selected.Value = ".stp",  
  3.     Set(  
  4.         Score,  
  5.         5  
  6.     ),  
  7.     Set(  
  8.         Score,  
  9.         0  
  10.     )  
  11. );  
  12. Reset(Radio1);  
  13. Navigate(  
  14.     Question2,  
  15.     ScreenTransition.Fade  
  16. )  

Question2 Screen 

 
The output screen will be like this,
 
QUestion1
  • Here we will check if the answer is true then we will add 5 points to the existing score and then reset the radio and navigate to the next screen. We will do the same for screen questions 3 to 5. 
Execute a formula on Onselect of Next button as below,
    1. If(  
    2.     Radio2.Selected.Value = "iisreset",  
    3.     Set(  
    4.         Score,  
    5.         Score + 5  
    6.     )  
    7. );  
    8. Reset(Radio2);  
    9. Navigate(  
    10.     Question3,  
    11.     ScreenTransition.Fade  
    12. )  

    Question 3 screen

     
    The output screen will be like this,
     
    QUestion3
     
    Execute a formula on Onselect of Next button as below,
      1. If(  
      2.     Radio3.Selected.Value = "443",  
      3.     Set(  
      4.         Score,  
      5.         Score + 5  
      6.     )  
      7. );  
      8. Reset(Radio3);  
      9. Navigate(  
      10.     Question4,  
      11.     ScreenTransition.Fade  
      12. )  

      Question 4 screen

       
      The output screen will be like this,
       
      Question4
       
      Execute a formula on Onselect of Next button as below,
        1. If(  
        2.     Radio4.Selected.Value = "All the above",  
        3.     Set(  
        4.         Score,  
        5.         Score + 5  
        6.     )  
        7. );  
        8. Reset(Radio4);  
        9. Navigate(  
        10.     Question5,  
        11.     ScreenTransition.Fade  
        12. )  

        Question 5 screen

         
        The output screen will be like this, 
         
        Question5
         
        Execute a formula on Onselect of Next button as below,
          1. If(  
          2.     Radio5.Selected.Value = "One",  
          3.     Set(  
          4.         Score,  
          5.         Score + 5  
          6.     )  
          7. );  
          8. Reset(Radio5);  
          9. Navigate(  
          10.     ResultScreen,  
          11.     ScreenTransition.Fade  
          12. )  

          Result screen

          The controls inside the screen will be like this,
           
          Result Screen Controls
           
          The output screen will be like this,
           
           
          Now will execute a formula of Default property of the Rating control to show stars as per score as below,
          1. If(  
          2.     Score = 5,  
          3.     1,  
          4.     If(  
          5.         Score = 10,  
          6.         2,  
          7.         If(  
          8.             Score = 15,  
          9.             3,  
          10.             If(  
          11.                 Score = 20,  
          12.                 4,  
          13.                 If(  
          14.                     Score = 25,  
          15.                     5  
          16.                 )  
          17.             )  
          18.         )  
          19.     )  
          20. )  
          To show score we will set the Text property of Label as below,
            1. Score & "/25"   
            After the quiz completion, we will navigate to the home screen so on the click of iconCheck so will execute the formula on the OnSelect property of this icon as below,
              1. Navigate(HomeScreen)  
              Output
               
              Output - Quiz