Hi @Anonymous ,
Firstly this bit is good - I have added some comments
If(
Connection.Connected, //if online
Patch(
Journeys, //write new record to database
Defaults(Journeys),
{ //with content fromcontrols
cre08_name:TextInput2.Text,
cre08_companyid:TextInput3.Text,
cre08_driverpmid:TextInput4.Text,
cre08_journeystartdateandtime:DatePicker1.SelectedDate
}
), //or if not online
Collect( //add the same data to a collection
JourneyColletion,
{
cre08_name:TextInput2.Text,
cre08_companyid:TextInput3.Text,
cre08_driverpmid:TextInput4.Text,
cre08_journeystartdateandtime:DatePicker1.SelectedDate
}
); //and save the updated data to the device
SaveData(
JourneyColletion,
"Saveitemstokeep"
)
)
Now this bit OnStart
LoadData( //loads your device data to collection
JourneyColletion,
"Saveitemstokeep",
true //ignores missing device file
);
If(
!IsEmpty(JourneyColletion.cre08_name), //if there is something in the collection
ForAll( //get the collection
JourneyColletion,
Patch( //and add to the data source
Journeys, //what about if you are offline?
Defaults(Journeys),
{
cre08_name:cre08_name, //ambiguity from here down
cre08_companyid:cre08_companyid,
cre08_driverpmid:cre08_driverpmid,
cre08_journeystartdateandtime: cre08_journeystartdateandtime
}
)
)
) //also the data is still on the device after writing it will write again
Instead, change your Collection above to this
Collect(
JourneyColletion,
{
cre08name:TextInput2.Text,
cre08companyid:TextInput3.Text,
cre08driverpmid:TextInput4.Text,
cre08journeystartdateandtime:DatePicker1.SelectedDate
}
);
then do this OnStart
LoadData(
JourneyColletion,
"Saveitemstokeep",
true
);
If(
!IsEmpty(JourneyColletion.cre08_name) && Connection.Connected,
ForAll(
JourneyColletion,
Patch(
Journeys,
Defaults(Journeys),
{
cre08_name:cre08name,
cre08_companyid:cre08companyid,
cre08_driverpmid:cre08driverpmid,
cre08_journeystartdateandtime:cre08journeystartdateandtime
}
)
);
Clear(JourneyColletion); //empty the collection and saved sata
SaveData(
JourneyColletion,
"Saveitemstokeep"
)
)
Please click Accept as solution 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 Thumbs Up.