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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Update record in offli...
Power Apps
Answered

Update record in offline mode

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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!

Categories:
I have the same question (0)
  • FernandoTC Profile Picture
    222 on at

    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

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    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");
    );

     

  • Verified answer
    FernandoTC Profile Picture
    222 on at

    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

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    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?

  • FernandoTC Profile Picture
    222 on at

    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.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 395

#2
WarrenBelz Profile Picture

WarrenBelz 352 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 287 Super User 2026 Season 1

Last 30 days Overall leaderboard