cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nithishguptak
Helper II
Helper II

saving form with offline/Online

Hello everyone,

 

I have a problem that I could edit a form delete a row but I couldnt insert a new row . What am I missing here ? 

 

First step is save to a collection. 

 

// update collection with form data
Patch(
    colHomeInspections,
    LookUp(colHomeInspections, ID=varCurrentRecord.ID),
    Form1.Updates
);
// save collection to local device
SaveData(
    colHomeInspections,
    "localHomeInspections"
);

/* more code added below */

// track record that was edited
Collect(
    colUnsavedRecords,
    {ID: varCurrentRecord.ID}
);
// save collection to local device
SaveData(
    colUnsavedRecords,
    "localUnsavedRecords"
);
Navigate('Saving Screen');

 

 Here I patch it to sharepoint list 

 

 

UpdateContext({locMessage: "Saving your data..."});

// Check if device is online
If(Connection.Connected,
    // Add or update records in SharePoint
    Patch(
        tilla_records,
        ShowColumns(
            Filter(
                colHomeInspections,
                'OfflineID ' in colHomeInspections.'OfflineID '
            ),
            "ID",
            "EventID",
            "Title",
            "Firma",
            "Name",
            "Notizen",
            "Datum",
            "dcfcNummer",
            "Kundenstatus",
            "ErstellerMail",
            "Prioritaet",
            "OfflineID",
            "Check"

        )
    );
    // Clear unsaved records collection
    Clear(colUnsavedRecords);
    SaveData(
        colUnsavedRecords,
        "localUnsavedRecords"
    );

    // Delete records from SharePoint
    ForAll(
        colDeletedRecords,
        Remove(
            tilla_records,
            LookUp(
                tilla_records,ID=colDeletedRecords[@ID]
            )
        )
    );
    
    // Clear deleted records collection
    Clear(colDeletedRecords);
    SaveData(
        colDeletedRecords,
        "localDeletedRecords"
    );    

);

//Collect(colBidon,Filter(colHomeInspections,OfflineID in colUnsavedRecords.OfflineID));

UpdateContext({locMessage: "Saving completed"});
Navigate('Loading Screen');

 

2 REPLIES 2
Nogueira1306
Super User
Super User

Hey!

 

To add a new row using Patch you need to do this:

 

Patch(

DataSource,

Defaults(DataSource),

{

...

}

)

 

https://docs.microsoft.com/en-us/power-platform/power-fx/reference/function-patch

 

If you need additional help please tag me in your reply and please like my reply.
If my reply provided you with a solution, pleased mark it as a solution ✔️!

Best regards,

Gonçalo Nogueira

Check my LinkedIn!

My website!

nithishguptak
Helper II
Helper II

@Nogueira1306 Where should I add the patch ? Its already in my code. 

 

 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,353)