cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Update record in offline mode

Hi All, 

I am creating an app for offline mode. On one screen I fill Journey details like name, ID, start end and in another screen I want to update the end date of the particular record in offline.
I wrote some code but in offline mode when I click save it creates new record rather than updating the existing record.

Code on save button-
  If(Connection.Connected,Patch(Journeys,First(Filter(Journeys,Journey_ID=ThisItem.cre08_journey_id)),{'Journey End Date and Time':'End Date'.SelectedDate +Time(Value('End Date Hour'.Selected.Value),Value('End Date Min'.Selected.Value),0,0)});Refresh(Journeys),
Collect(JourneyColletion,First(Filter(JourneyColletion,cre08_journey_id=ThisItem.cre08_journey_id)),{cre08_journeyenddateandtime:'End Date'.SelectedDate +Time(Value('End Date Hour'.Selected.Value),Value('End Date Min'.Selected.Value),0,0)
});Reset('On Going Journey');
SaveData(JourneyColletion,"Saveitemstokeep")
);

Any help will be appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions

Ok @Anonymous  lets then begin to clarify things about what you want to achieve.

here is the code of your Journey Detail Screen:

If(
       Connection.Connected,
       Patch(
                  Journeys,
                  Defaults(Journeys),
                 {
                   cre08_journey_id:Text(GUID()),
                   cre08_name:TextInput2.Text,
                   cre08_companyid:TextInput3.Text,
                   cre08_driverpmid:TextInput4.Text,
                   cre08_journeystartdateandtime:DatePicker1.SelectedDate+
                                                                      Time(Value(ddHour.Selected.Value),Value(ddMinute.Selected.Value),0,0),

                   'Route ID Lookup': LookUp(Routes,Route=GUID(TextInput8.Text)),
                   'Bus ID Lookup':LookUp(Buses,Bus=GUID(TextInput7.Text))
              }
),
        Collect(
                     JourneyColletion,
                     {
                       cre08_journey_id:Text(GUID()),
                       cre08_name:TextInput2.Text,
                       cre08_companyid:TextInput3.Text,
                       cre08_driverpmid:TextInput4.Text,
                       cre08_journeystartdateandtime:DatePicker1.SelectedDate+
                                                                          Time(Value(ddHour.Selected.Value),Value(ddMinute.Selected.Value),0,0),
                       cre08_routeid:LookUp(RouteCollection,Route=GUID(TextInput8.Text)),
                       cre08_busid:LookUp(BusCollection,Bus=GUID(TextInput7.Text)),
                       cre08_routename:ComboBox4.Selected.Name
                 }
);
SaveData(JourneyColletion,"Saveitemstokeep");
);



As I can understand here. You want to save the journey details into data source Journeys  if the app has connection. Otherwise, it is saved in JourneyCollection if the app has not connection.

Then, in the next screen, you want to modify  the end date of the journey, and again, if you have connection, it is modified in the online data source Journeys, and if don't you want to modify it in your offline collection JourneyCollection. Am I right until here?

If it is like I am supposing. The problem here is that in the first screen (Journey Detail Screen) you collect one record into your data source or your offline collection. Then, in the next screen, you modify it by adding one new field with the end date. 

Here is the point:

  • With connection, you add a new record to Journeys, and in the next screen then modify the field cre08_journeyenddateandtime of that record. I supose your data source has an existing field with that name.
  • However, when you don't have connection, you first store the new record into JourneyCollection offline and then try to modify it by adding an end date in the field cre08_journeyenddateandtime. The thing here is that when you first collected the item in JourneyDetails page into this JourneyCollection, you did not specify a field named cre08_journeyenddateandtime so it is not possible to alter that field value in the second screen, as this field does not exist.

    The solution? Easy, just add this field in the code of the JourneyDetail Screen so when you collect into JourneyCollection the values of ID, name, start date... the field cre08_journeyenddateandtime  is also created with a blank value so it can be modified after. Here is the added change.

 

   If(
       Connection.Connected,
       Patch(
                  Journeys,
                  Defaults(Journeys),
                 {
                   cre08_journey_id:Text(GUID()),
                   cre08_name:TextInput2.Text,
                   cre08_companyid:TextInput3.Text,
                   cre08_driverpmid:TextInput4.Text,
                   cre08_journeystartdateandtime:DatePicker1.SelectedDate+
                                                                      Time(Value(ddHour.Selected.Value),Value(ddMinute.Selected.Value),0,0),

                   'Route ID Lookup': LookUp(Routes,Route=GUID(TextInput8.Text)),
                   'Bus ID Lookup':LookUp(Buses,Bus=GUID(TextInput7.Text))
              }
),
        Collect(
                     JourneyColletion,
                     {
                       cre08_journey_id:Text(GUID()),
                       cre08_name:TextInput2.Text,
                       cre08_companyid:TextInput3.Text,
                       cre08_driverpmid:TextInput4.Text,
                       cre08_journeystartdateandtime:DatePicker1.SelectedDate+
                                                                          Time(Value(ddHour.Selected.Value),Value(ddMinute.Selected.Value),0,0),
                       cre08_journeyenddateandtime: Blank(),
                       cre08_routeid:LookUp(RouteCollection,Route=GUID(TextInput8.Text)),
                       cre08_busid:LookUp(BusCollection,Bus=GUID(TextInput7.Text)),
                       cre08_routename:ComboBox4.Selected.Name
                 }
);

Then the formula in your second screen should work properly as the field cre08_journeyenddateandtime  already exists.

 

Also your data source Journeys need to have a field with that name so it can me modified when wanted.

 

If I am not wrong with your intention here, guess this will work now

 

View solution in original post

5 REPLIES 5
FernandoTC
Resolver II
Resolver II

Hi @Anonymous 

In the code you specified there, You have an inf clause. First condition: If Connection.connected-> You use Patch() Function to update the record.

In the second statement for the condition Connection.connected=false, you are using Collect() function, but I think you meant to use Patch() there as well. Just replace that Collect() function with Patch(). Exact same arguments, just change the function before the brackets:

If(
Connection.Connected,
Patch(Journeys,First(Filter(Journeys,Journey_ID=ThisItem.cre08_journey_id)),{'Journey End Date and Time':'End Date'.SelectedDate +Time(Value('End Date Hour'.Selected.Value),Value('End Date Min'.Selected.Value),0,0)});
Refresh(Journeys),
Patch(JourneyColletion,First(Filter(JourneyColletion,cre08_journey_id=ThisItem.cre08_journey_id)),{cre08_journeyenddateandtime:'End Date'.SelectedDate +Time(Value('End Date Hour'.Selected.Value),Value('End Date Min'.Selected.Value),0,0)
});Reset('On Going Journey');
SaveData(JourneyColletion,"Saveitemstokeep")
);

 

Hope it works as intended now

 

Anonymous
Not applicable

Hi @FernandoTC ,

Thanks for the response!

I have tried that and face error saying "the column cre08_journeyenddateandtime does not exist" and "patch has invalid arguments".

And Journey detail screen which I mentioned has below code-

If(Connection.Connected,
Patch(Journeys,Defaults(Journeys),{cre08_journey_id:Text(GUID()),
cre08_name:TextInput2.Text,cre08_companyid:TextInput3.Text,cre08_driverpmid:TextInput4.Text,cre08_journeystartdateandtime:DatePicker1.SelectedDate +Time(Value(ddHour.Selected.Value),Value(ddMinute.Selected.Value),0,0),'Route ID Lookup': LookUp(Routes,Route=GUID(TextInput8.Text)),'Bus ID Lookup':LookUp(Buses,Bus=GUID(TextInput7.Text))
}),
Collect(JourneyColletion,{cre08_journey_id:Text(GUID()),
cre08_name:TextInput2.Text, cre08_companyid:TextInput3.Text,cre08_driverpmid:TextInput4.Text,cre08_journeystartdateandtime:DatePicker1.SelectedDate +Time(Value(ddHour.Selected.Value),Value(ddMinute.Selected.Value),0,0),cre08_routeid: LookUp(RouteCollection,Route=GUID(TextInput8.Text)),cre08_busid:LookUp(BusCollection,Bus=GUID(TextInput7.Text)),cre08_routename:ComboBox4.Selected.Name
});
SaveData(JourneyColletion,"Saveitemstokeep");
);

 

Ok @Anonymous  lets then begin to clarify things about what you want to achieve.

here is the code of your Journey Detail Screen:

If(
       Connection.Connected,
       Patch(
                  Journeys,
                  Defaults(Journeys),
                 {
                   cre08_journey_id:Text(GUID()),
                   cre08_name:TextInput2.Text,
                   cre08_companyid:TextInput3.Text,
                   cre08_driverpmid:TextInput4.Text,
                   cre08_journeystartdateandtime:DatePicker1.SelectedDate+
                                                                      Time(Value(ddHour.Selected.Value),Value(ddMinute.Selected.Value),0,0),

                   'Route ID Lookup': LookUp(Routes,Route=GUID(TextInput8.Text)),
                   'Bus ID Lookup':LookUp(Buses,Bus=GUID(TextInput7.Text))
              }
),
        Collect(
                     JourneyColletion,
                     {
                       cre08_journey_id:Text(GUID()),
                       cre08_name:TextInput2.Text,
                       cre08_companyid:TextInput3.Text,
                       cre08_driverpmid:TextInput4.Text,
                       cre08_journeystartdateandtime:DatePicker1.SelectedDate+
                                                                          Time(Value(ddHour.Selected.Value),Value(ddMinute.Selected.Value),0,0),
                       cre08_routeid:LookUp(RouteCollection,Route=GUID(TextInput8.Text)),
                       cre08_busid:LookUp(BusCollection,Bus=GUID(TextInput7.Text)),
                       cre08_routename:ComboBox4.Selected.Name
                 }
);
SaveData(JourneyColletion,"Saveitemstokeep");
);



As I can understand here. You want to save the journey details into data source Journeys  if the app has connection. Otherwise, it is saved in JourneyCollection if the app has not connection.

Then, in the next screen, you want to modify  the end date of the journey, and again, if you have connection, it is modified in the online data source Journeys, and if don't you want to modify it in your offline collection JourneyCollection. Am I right until here?

If it is like I am supposing. The problem here is that in the first screen (Journey Detail Screen) you collect one record into your data source or your offline collection. Then, in the next screen, you modify it by adding one new field with the end date. 

Here is the point:

  • With connection, you add a new record to Journeys, and in the next screen then modify the field cre08_journeyenddateandtime of that record. I supose your data source has an existing field with that name.
  • However, when you don't have connection, you first store the new record into JourneyCollection offline and then try to modify it by adding an end date in the field cre08_journeyenddateandtime. The thing here is that when you first collected the item in JourneyDetails page into this JourneyCollection, you did not specify a field named cre08_journeyenddateandtime so it is not possible to alter that field value in the second screen, as this field does not exist.

    The solution? Easy, just add this field in the code of the JourneyDetail Screen so when you collect into JourneyCollection the values of ID, name, start date... the field cre08_journeyenddateandtime  is also created with a blank value so it can be modified after. Here is the added change.

 

   If(
       Connection.Connected,
       Patch(
                  Journeys,
                  Defaults(Journeys),
                 {
                   cre08_journey_id:Text(GUID()),
                   cre08_name:TextInput2.Text,
                   cre08_companyid:TextInput3.Text,
                   cre08_driverpmid:TextInput4.Text,
                   cre08_journeystartdateandtime:DatePicker1.SelectedDate+
                                                                      Time(Value(ddHour.Selected.Value),Value(ddMinute.Selected.Value),0,0),

                   'Route ID Lookup': LookUp(Routes,Route=GUID(TextInput8.Text)),
                   'Bus ID Lookup':LookUp(Buses,Bus=GUID(TextInput7.Text))
              }
),
        Collect(
                     JourneyColletion,
                     {
                       cre08_journey_id:Text(GUID()),
                       cre08_name:TextInput2.Text,
                       cre08_companyid:TextInput3.Text,
                       cre08_driverpmid:TextInput4.Text,
                       cre08_journeystartdateandtime:DatePicker1.SelectedDate+
                                                                          Time(Value(ddHour.Selected.Value),Value(ddMinute.Selected.Value),0,0),
                       cre08_journeyenddateandtime: Blank(),
                       cre08_routeid:LookUp(RouteCollection,Route=GUID(TextInput8.Text)),
                       cre08_busid:LookUp(BusCollection,Bus=GUID(TextInput7.Text)),
                       cre08_routename:ComboBox4.Selected.Name
                 }
);

Then the formula in your second screen should work properly as the field cre08_journeyenddateandtime  already exists.

 

Also your data source Journeys need to have a field with that name so it can me modified when wanted.

 

If I am not wrong with your intention here, guess this will work now

 

View solution in original post

Anonymous
Not applicable

Hi @FernandoTC ,

Thanks for your response!

Yes, you are right, the field cre08_journeyenddateandtime exists in data source and not in collection hence "cre08_journeyenddateandtime " throwing error. Also, cre08_journeyenddateandtime=Blank () gives me error as my column has datetime datatype. 

Is there a way where I can have that column in collection just for name sake. Because later I am using that column in filter -

filter(gallery, isblank(cre08_journeyenddateandtime)) 

Or any other solution?

Hi @Anonymous 

When adding the record to the collection, instead of adding a Blank() value in that column, add something like 01/01/1970 as a placeholder.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,255)