web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Reset if Patch is succ...
Power Apps
Unanswered

Reset if Patch is successful

(0) ShareShare
ReportReport
Posted on by 2,563

Need some help here, I only want to reset TextInputTicket if patch is successful. Currently it will reset even if Patch is not successful.

If(
 TabListMenu.Selected.Value = "Message" && !IsBlank(TextInputTicket.Value),
 Refresh(Helpdesk);
 // Refresh the data source before Patch
Patch(
 Helpdesk,
 CurrentItem,// Use the context variable set in the Gallery
 {
 'Case Comments': "<b>" & Char(13) & Char(13) & User().FullName & "</b>" & "<br> <span style='font-size:10.5pt'>" & Text(
 Now(),
 "[$-en-US]yyyy/mm/dd hh:mm"
 ) & "</span> <br> " & Char(13) & TextInputTicket.Value & CurrentItem.'Case Comments',
 LastComment: TextInputTicket.Value,
 'Last Modified By': {
 '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
 Department: "",
 DisplayName: User().FullName,
 Claims: "i:0#.f|membership|" & Lower(User().Email),
 Email: User().Email,
 JobTitle: "",
 Picture: ""
 },
 'Last Comment Made By': {
 '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
 Department: "",
 DisplayName: User().FullName,
 Claims: "i:0#.f|membership|" & Lower(User().Email),
 Email: User().Email,
 JobTitle: "",
 Picture: ""
 }
 }
 );

 // Check for errors during the patch operation
 If(
 !IsEmpty(Errors(Helpdesk)),
 // Errors occurred, handle them and do not reset TextInputTicket
 Notify(
 First(Errors(Helpdesk)).Message,
 NotificationType.Error
 ),
 // No errors, proceed with additional actions
 UpdateContext(
 {
 CurrentItem: LookUp(
 Helpdesk,
 ID = CurrentItem.ID
 )
 }
 );
 Reset(TextInputTicket)
 )
);
 If(
 TabListMenu.Selected.Value = "Worklog" && !IsBlank(TextInputTicket.Value),
 Refresh(Helpdesk);
 // Refresh the data source before Patch
Patch(
 Helpdesk,
 CurrentItem,// Use the context variable set in the Gallery
 {
 Worklog: "<b>" & Char(13) & Char(13) & User().FullName & "</b>" & "<br> <span style='font-size:10.5pt'>" & Text(
 Now(),
 "[$-en-US]yyyy/mm/dd hh:mm"
 ) & "</span> <br> " & Char(13) & TextInputTicket.Value & CurrentItem.Worklog,
 'Last Modified By': {
 '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
 Department: "",
 DisplayName: User().FullName,
 Claims: "i:0#.f|membership|" & Lower(User().Email),
 Email: User().Email,
 JobTitle: "",
 Picture: ""
 }
 }
 );

 // Check for errors during the patch operation
 If(
 !IsEmpty(Errors(Helpdesk)),
 // Errors occurred, handle them and do not reset TextInputTicket
 Notify(
 First(Errors(Helpdesk)).Message,
 NotificationType.Error
 ),
 // No errors, proceed with additional actions
 UpdateContext(
 {
 CurrentItem: LookUp(
 Helpdesk,
 ID = CurrentItem.ID
 )
 }
 );
 Reset(TextInputTicket)
 )
);

 If(
 TabListMenu.Selected.Value = "Close" && !IsBlank(TextInputTicket.Value),
 Refresh(Helpdesk);
 // Refresh the data source before Patch
Patch(
 Helpdesk,
 CurrentItem,// Use the context variable set in the Gallery
 {
 Resolution: "<b>" & Char(13) & Char(13) & User().FullName & "</b>" & "<br> <span style='font-size:10.5pt'>" & Text(
 Now(),
 "[$-en-US]yyyy/mm/dd hh:mm"
 ) & "</span> <br> " & Char(13) & TextInputTicket.Value & CurrentItem.Resolution,
 'Last Modified By': {
 '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
 Department: "",
 DisplayName: User().FullName,
 Claims: "i:0#.f|membership|" & Lower(User().Email),
 Email: User().Email,
 JobTitle: "",
 Picture: ""
 },
 Status: {
 '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
 Id: 4,
 Value: "Closed"
 }
 },
 {
 'Assigned To': {
 '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
 Claims: "i:0#.f|membership|" & Lower(User().Email),
 Department: "",
 DisplayName: User().FullName,
 Email: User().Email,
 JobTitle: "",
 Picture: ""
 }
 }
 );
 // Check for errors during the patch operation
 If(
 !IsEmpty(Errors(Helpdesk)),
 // Errors occurred, handle them and do not reset TextInputTicket
 Notify(
 First(Errors(Helpdesk)).Message,
 NotificationType.Error
 ),
 // No errors, proceed with additional actions
 UpdateContext(
 {
 CurrentItem: LookUp(
 Helpdesk,
 ID = CurrentItem.ID
 )
 }
 );
 Reset(TextInputTicket)
 )
);

If(
 TabListMenu.Selected.Value = "Close",
 // Additional logic for filtering TicketsCollection based on TabList1.Selected.Value
 If(
 TabList1.Selected.Value = "Unassigned",
 ClearCollect(
 TicketsCollection,
 Filter(
 Helpdesk,
 Status.Value = "Unassigned"
 )
 );
 UpdateContext({itemSelected: false})
 );
 If(
 TabList1.Selected.Value = "My Tickets",
 ClearCollect(
 TicketsCollection,
 Filter(
 Helpdesk,
 ('Assigned To'.DisplayName = User().FullName) && ((Status.Value = "Assigned") || (Status.Value = "In Progress") || (Status.Value = "Waiting for user response") || (Status.Value = "Waiting for external resource") || (Status.Value = "Backlog"))
 )
 );
 UpdateContext({itemSelected: false})
 );
 If(
 TabList1.Selected.Value = "Closed",
 ClearCollect(
 TicketsCollection,
 Filter(
 Sort(
 Helpdesk,
 ID,
 SortOrder.Descending
 ),
 'Assigned To'.DisplayName = User().FullName && Status.Value = "Closed"
 )
 );
 UpdateContext({itemSelected: false});
 Notify("Ticket was closed and placed under Closed tickets.", NotificationType.Success, 600)
 );
 If(
 TabList1.Selected.Value = "All",
 ClearCollect(
 TicketsCollection,
 SortByColumns(
 Helpdesk,
 "Created",
 SortOrder.Descending
 )
 );
 UpdateContext({itemSelected: false})
 )
)
Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    hey @JimmyWork 

     

    try this modification please:

    If(
     !IsBlank(TextInputTicket.Value),
     Refresh(Helpdesk); // Refresh the data source before any Patch operation
     // Determine the action based on the selected tab
     Switch(
     TabListMenu.Selected.Value,
     "Message",
     Set(varPatchResult,
     Patch(
     Helpdesk,
     CurrentItem,
     {
     'Case Comments': "<b>" & Char(13) & Char(13) & User().FullName & "</b>" & "<br> <span style='font-size:10.5pt'>" & Text(Now(), "[$-en-US]yyyy/mm/dd hh:mm") & "</span> <br> " & Char(13) & TextInputTicket.Value & CurrentItem.'Case Comments',
     LastComment: TextInputTicket.Value,
     'Last Modified By': {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
     Department: "",
     DisplayName: User().FullName,
     Claims: "i:0#.f|membership|" & Lower(User().Email),
     Email: User().Email,
     JobTitle: "",
     Picture: ""
     },
     'Last Comment Made By': {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
     Department: "",
     DisplayName: User().FullName,
     Claims: "i:0#.f|membership|" & Lower(User().Email),
     Email: User().Email,
     JobTitle: "",
     Picture: ""
     }
     }
     )
     ),
     "Worklog",
     Set(varPatchResultWorklog,
     Patch(
     Helpdesk,
     CurrentItem,
     {
     Worklog: "<b>" & Char(13) & Char(13) & User().FullName & "</b>" & "<br> <span style='font-size:10.5pt'>" & Text(Now(), "[$-en-US]yyyy/mm/dd hh:mm") & "</span> <br> " & Char(13) & TextInputTicket.Value & CurrentItem.Worklog,
     'Last Modified By': {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
     Department: "",
     DisplayName: User().FullName,
     Claims: "i:0#.f|membership|" & Lower(User().Email),
     Email: User().Email,
     JobTitle: "",
     Picture: ""
     }
     }
     )
     ),
     "Close",
     Set(varPatchResultClose,
     Patch(
     Helpdesk,
     CurrentItem,
     {
     Resolution: "<b>" & Char(13) & Char(13) & User().FullName & "</b>" & "<br> <span style='font-size:10.5pt'>" & Text(Now(), "[$-en-US]yyyy/mm/dd hh:mm") & "</span> <br> " & Char(13) & TextInputTicket.Value & CurrentItem.Resolution,
     'Last Modified By': {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
     Department: "",
     DisplayName: User().FullName,
     Claims: "i:0#.f|membership|" & Lower(User().Email),
     Email: User().Email,
     JobTitle: "",
     Picture: ""
     },
     Status: {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
     Id: 4, // Assuming 4 represents 'Closed'
     Value: "Closed"
     }
     },
     {
     'Assigned To': {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
     Claims: "i:0#.f|membership|" & Lower(User().Email),
     Department: "",
     DisplayName: User().FullName,
     Email: User().Email,
     JobTitle: "",
     Picture: ""
     }
     }
     )
     )
     );
     // Check for errors after Patch operation for each scenario
     If(
     IsEmpty(Errors(Helpdesk)),
     // If no errors, reset TextInputTicket and possibly other actions
     Reset(TextInputTicket),
     // If there are errors, notify the user without resetting TextInputTicket
     Notify("Error updating item. Please try again.", NotificationType.Error)
     )
    );

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • Micky Profile Picture
    365 Moderator on at

    try using

    IfError(patchCodeHere,true,false)

  • JimmyW Profile Picture
    2,563 on at

    Thank you will try this, tried to wrap everything before but did not get it work. Will try this and let you know.
    Do you think the first refresh of the database is needed? Not sure i that is the one causing more patch errors.

     

    And do i really need to use Set and create variables when I have the CurrentItem?

    Asking because i really dont understand why it's not working

  • Micky Profile Picture
    365 Moderator on at

    You must use set when you are changing a value of a global variable and you must use UpdateContext if you're using a variable that's initialized inside a screen.

  • JimmyW Profile Picture
    2,563 on at

    This is know, but my original code i do not use a variable the code provided by @mmbr1606 have variables in it, this is what I'm asking about, why i need to introduce a variable.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard