Introduction
In this article, I will be representing to copy of the items in PowerApps. I have tried to provide the scenario with solutions in the below steps.
Scenario
It is an interesting requirement to copy items by requester or user, which saves their time for duplicate entries. In this post, we'll look at how to copy items with a confirmation message and how to open the copied item directly in the form.
Objective
I've employed a common gallery with two icons, one of which will open the item in the form to view/edit the details, and there is another icon to copy the item. When copy is clicked, a popup message will appear to confirm if the user really wants to copy. If the user says yes, the item will be copied, and another popup will appear confirming if they would like to open the item in edit form. If the user clicks yes, the item will open in edit form. If the user selects cancel on either of the two popups, the user will be navigated back to the gallery. When a user does not want to open the item in the edit form, the copied item will appear as the first item in the gallery (if the gallery is sorted in descending order).
Here is my gallery with a copy icon to perform the specific action. Kindly refer to my article to create a request/save the item in the list and open the item from the gallery to edit the form. In this gallery, Only the creator can copy their own item. So, on visible property, a formula is written that validates if a logged user is also the creator of the item.
Since we are creating two pop up we shall be creating two groups. Let us see each group one by one. We shall be using variables to hide and show Pop Up.
Step 1. Create a First or Confirmation pop-up to copy the item/request
Important: The sequence of the controls in the group should be as shown in the image below, even if the controls are added randomly. Use the bring front menu and bring in the order shown in the image below. I shall work, organize, and work on UI for each control individually and then group them all together.
So, here I am aligning the Background rectangle(RectCopyConfirmation), which covers the entire screen as faded so that background actions are deactivated. Since all other controls have been added and renamed already, all the controls are visible on top of the background gray-out rectangle(RectCopyConfirmation).
Same way in the below picture, you can also see the Popup rectangle(RectCopyConfirmSmall) is also pulled and brought to the middle of the screen. Height and width are set for smaller rectangles (RectCopyConfirmSmall) too.
After aligning both the buttons and label, change the text of the label. Subtitle2 is the control where ID is getting stored. Subtitle 2 is the control inside the gallery.
Change the label text color to white so that it is better in its visibility.
Select the required control by holding the Shift Key and mouse click and group them together by using the group menu.
We can select each control inside the group and make changes if required.
Step 2. Create a Second or proposal Pop-up to edit the copied item/request.
Rename the first group to the appropriate name. In this example, it is named as GrpCopyConfirmation. To create the next popup, select the group and copy and paste, which duplicates all the controls along with the group. After copying and pasting, rename the second group and controls. Both groups will be inside the screen and outside the gallery.
After renaming the second popup controls, Both the groups look like below. And change the label of the second pop-up because we are asking a different question to the user. The below screenshot shows the questions as well.
Step 3. The first pop-up button functions.
We will write a patch function to copy the item. As soon as the item is copied, item gets saved in the SharePoint list.
No button does nothing except hide the popup, which eventually makes the gallery appear. To hide and show, we are going to use variables with true and false values.
Yes button patches the item, which works as copying the item. Here we shall write the formula for patching.
Step 4. The second pop-up button functions
No button does nothing except hide the popup, which eventually makes the gallery appear. To hide and show, we are going to use variables with true and false values.
In this screenshot, we can see a condition is checked if created by is same as the logged-in user. That is because Cloning or copying of an item is allowed only on the user’s own item. In the gallery screenshot, we can see the copy/clone icon has a visibility property set so that the copy icon is visible for only those items that are created by logged-in users.
Step 5. Set the visibility of all controls to appear in sequence
Visibility is not only dependent upon visible property but also on properties OnSelect and OnChange.
We should also understand in the group, whatever value is assigned to the group, sub-controls automatically inherit the value for the same property. In the above screenshot, you may see the same variables are set to either true or false. We are just assigning the same variable to both of the groups.
Firstly, we shall set the variable on the gallery.
Assign a variable to the first popup.
Assign a variable to a second popup (Edit function takes place post copy).
Conclusion
From the above article, we saw how to copy requests/items using the patch function. There were two popups created for confirmation purposes. After copying the requests the copied request could be opened in edit mode as well as shown in the above article.