1

I have an application which have 3 leave types to select for the leave request,I am using a form control but submitting the data using the Patch Function. I am showing the form fields according to the leave request selected in the dropdown in my form.

and on submit button I have set this Code:

   If(DataCardValue1.Selected.Value = "Time Off",
Patch(
   LeaveRequests,
   {
       ID:LeaveGallery.Selected.ID
       
    
   },
{
   LeaveID: CurrentUserID,    
   User:     DataCardValue6.Text,
   Requestor: MyUserEmail,
   Approver:
   {
 Claims: Concatenate(
          "i:0#.f|membership|",
          DataCardValue3.Selected.Email // Person email
          ),
          Department: "",
          DisplayName: "",
          Email: DataCardValue3.Selected.Email, // Person email
          JobTitle: "",
          Picture: ""
},
 Description: DataCardValue2.Text,
   TimeOffDate: DataCardValue22.SelectedDate,
   TimeOffFrom: DataCardValue19.Selected,
   TimeOffTo: DataCardValue20.Selected,
   TotalTimeRequested: Label23.Text,
   LeaveStatus:"Pending"
    }
  ),DataCardValue1.Selected.Value = "Annual Leave",
Patch(
   LeaveRequests,
   {
       ID:LeaveGallery.Selected.ID
       
    
   },
{
   LeaveID: CurrentUserID,    
   User:     DataCardValue6.Text,
 Requestor: MyUserEmail,
   Approver:
   {
 Claims: Concatenate(
          "i:0#.f|membership|",
          DataCardValue3.Selected.Email // Person email
          ),
          Department: "",
          DisplayName: "",
          Email: DataCardValue3.Selected.Email, // Person email
          JobTitle: "",
          Picture: ""
},
 Description: DataCardValue2.Text,
   StartDate:StartDate.SelectedDate,
   EndDate:EndDate.SelectedDate,
   DaysCount:Label25.Text,
   LeaveStatus:"Pending"
    }
),
DataCardValue1.Selected.Value = "Sick Leave",
Patch(
   LeaveRequests,
   {
       ID:LeaveGallery.Selected.ID
       
    
   },
{
   LeaveID: CurrentUserID,    
   User:     DataCardValue6.Text,
 Requestor: MyUserEmail,
   Approver:
   {
 Claims: Concatenate(
          "i:0#.f|membership|",
          DataCardValue3.Selected.Email // Person email
          ),
          Department: "",
          DisplayName: "",
          Email: DataCardValue3.Selected.Email, // Person email
          JobTitle: "",
          Picture: ""
},
 Description: DataCardValue2.Text,
   StartDate:StartDate.SelectedDate,
   EndDate:EndDate.SelectedDate,
   DaysCount:Label25.Text,
   LeaveStatus:"Pending"
    }
),
DataCardValue1.Selected.Value = "Casual Leave",
Patch(
   LeaveRequests,
   {
       ID:LeaveGallery.Selected.ID
       
    
   },
{
   LeaveID: CurrentUserID,    
   User:     DataCardValue6.Text,
   Requestor: MyUserEmail,
   Approver:
   {
 Claims: Concatenate(
          "i:0#.f|membership|",
          DataCardValue3.Selected.Email // Person email
          ),
          Department: "",
          DisplayName: "",
          Email: DataCardValue3.Selected.Email, // Person email
          JobTitle: "",
          Picture: ""
},
 Description: DataCardValue2.Text,
   StartDate:StartDate.SelectedDate,
   EndDate:EndDate.SelectedDate,
   DaysCount:Label25.Text,
   LeaveStatus:"Pending"
    }
)
);
 Navigate(SucessScreen,None); 

after submitting it stores the data into SP list, but when I create another record it overwrites onto the existing one, without creating a new record.

any help?

0

In your patch code, you are using {ID:LeaveGallery.Selected.ID}, and that means you are patching that specific record in the LeaveRequests Datasource (SharePoint list in your case I believe).

For the patch to create a new record, you need to use the Defaults() function. So it would be:

Patch(LeaveRequests, Defaults(LeaveRequests), {//your patching code here}).

One thing I like to do is to have a single Patch function that handles both "Insert" and "Update" methods. So you can use something like this:

If(IsUpdate, Set(varItemToBePatched, LookUp(LeaveRequests, ID = LeaveGallery.Selected.ID),Set(varItemToBePatched, Defaults(LeaveRequests))));
Patch(LeaveRequests,varItemToBePatched,{//your patching code here})

Another tip, instead of having all the patches for each "DataCardValue1.Selected.Value", put that "if" inside your patch as well, so you have a single patch function to change/maintain:

Patch(
LeaveRequests,
{
   ID:LeaveGallery.Selected.ID
   

},
{
LeaveID: CurrentUserID,    
User:     DataCardValue6.Text,
Requestor: MyUserEmail,
Approver:
{
Claims: Concatenate(
      "i:0#.f|membership|",
      DataCardValue3.Selected.Email // Person email
      ),
      Department: "",
      DisplayName: "",
      Email: DataCardValue3.Selected.Email, // Person email
      JobTitle: "",
      Picture: ""
},
Description: DataCardValue2.Text,
TimeOffDate: DataCardValue22.SelectedDate,
TimeOffFrom: DataCardValue19.Selected,
TimeOffTo: DataCardValue20.Selected,
TotalTimeRequested: Label23.Text,
YourColumn:If(DataCardValue1.Selected.Value = "Time Off","something",DataCardValue1.Selected.Value = "Casual Leave","something else")
}
)

Hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.