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 Apps
Answered

Issue with Sync

(0) ShareShare
ReportReport
Posted on by 35
 
Hello,
Please Help me with this code. This is a part of a very long Sync Code
I want to add a record if the collection has no ID (the collection is getting data from the source), or update if the ID exists.
 
Syn_Plan is the collection name after saving and loading data. The user edit it and then sync to apply changes on the source. 
 
 
ForAll(
    Syn_Plan,
    If(IsBlank(ThisRecord.ID),
        Patch(
            Plan_list_Approval,
            Defaults(Plan_list_Approval),
            {
                DoctorCode: ThisRecord.DoctorCode,
                DoctorName: ThisRecord.DoctorName,
                Class: ThisRecord.Class,
                LocationCode: ThisRecord.LocationCode,
                LocationName: ThisRecord.LocationName,
                Medical_REP: ThisRecord.Medical_REP,
                Speciality: ThisRecord.Speciality,
                Visitdate: ThisRecord.Visitdate,
                PlanDate: ThisRecord.PlanDate,
                NUM: ThisRecord.NUM,
                Month: ThisRecord.Month,
                Team: First(Syn_User).Team,
                Approval: If(ThisRecord.Approval = "Rejected", "Pending", ThisRecord.Approval),
                Required_FOV: ThisRecord.Required_FOV,
                Parent_Account_Name: ThisRecord.Parent_Account_Name,
                Subclass_Potential: ThisRecord.Subclass_Potential,
                FOV: ThisRecord.FOV,
                Activity: ThisRecord.Activity
            }
        )
 
        ,Patch(
            Plan_list_Approval,LookUp(Plan_list_Approval, ID = ThisRecord.ID),
           
            {
                Approval: If(ThisRecord.Approval = "Rejected", "Pending", ThisRecord.Approval),
                Activity: ThisRecord.Activity
            }
        )));
 
Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,427 Most Valuable Professional on at
    Try using the As disambiguation operator
    ForAll(
       Syn_Plan As _Plan,
       If(
          IsBlank(_Plan.ID),
          Patch(
             Plan_list_Approval,
             Defaults(Plan_list_Approval),
             {
                DoctorCode: _Plan.DoctorCode,
                DoctorName: _Plan.DoctorName,
                Class: _Plan.Class,
                LocationCode: _Plan.LocationCode,
                LocationName: _Plan.LocationName,
                Medical_REP: _Plan.Medical_REP,
                Speciality: _Plan.Speciality,
                Visitdate: _Plan.Visitdate,
                PlanDate: _Plan.PlanDate,
                NUM: _Plan.NUM,
                Month: _Plan.Month,
                Team: First(Syn_User).Team,
                Approval: If(_Plan.Approval = "Rejected", "Pending", _Plan.Approval),
                Required_FOV: _Plan.Required_FOV,
                Parent_Account_Name: _Plan.Parent_Account_Name,
                Subclass_Potential: _Plan.Subclass_Potential,
                FOV: _Plan.FOV,
                Activity: _Plan.Activity
             }
          ),
          Patch(
             Plan_list_Approval,
             {
                ID: _Plan.ID,
                Approval: 
                If(
                   _Plan.Approval = "Rejected", 
                   "Pending", 
                   _Plan.Approval
                ),
                Activity: _Plan.Activity
             }
          )
       )
    );
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    Buy me a coffee
  • Verified answer
    Barakat Profile Picture
    35 on at
    Thank you, this solved my issue
     
     
    // Patch new plans
    ForAll(
        Syn_Plan,
        If(
            IsBlank(ThisRecord.ID),
            Patch(
                Plan_list_Approval,
                Defaults(Plan_list_Approval),
                {
                    DoctorCode: ThisRecord.DoctorCode,
                    DoctorName: ThisRecord.DoctorName,
                    Class: ThisRecord.Class,
                    LocationCode: ThisRecord.LocationCode,
                    LocationName: ThisRecord.LocationName,
                    Medical_REP: ThisRecord.Medical_REP,
                    Speciality: ThisRecord.Speciality,
                    Visitdate: ThisRecord.Visitdate,
                    PlanDate: ThisRecord.PlanDate,
                    NUM: ThisRecord.NUM,
                    Month: ThisRecord.Month,
                    Team: First(Syn_User).Team,
                    Approval: If(ThisRecord.Approval = "Rejected", "Pending", ThisRecord.Approval),
                    Required_FOV: ThisRecord.Required_FOV,
                    Parent_Account_Name: ThisRecord.Parent_Account_Name,
                    Subclass_Potential: ThisRecord.Subclass_Potential,
                    FOV: ThisRecord.FOV,
                    Activity: ThisRecord.Activity
                }
            ),
            // Update existing plans
            Patch(
                Plan_list_Approval,
                { ID: ThisRecord.ID },
                {
                    Approval: If(ThisRecord.Approval = "Rejected", "Pending", ThisRecord.Approval),
                    Activity: ThisRecord.Activity
                }
            )
        )
    );

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 386 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 361

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 339 Super User 2025 Season 2

Last 30 days Overall leaderboard