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 Platform Community / Forums / Power Apps / Not able to load data ...
Power Apps
Answered

Not able to load data into collection using LoadData()

(0) ShareShare
ReportReport
Posted on by

Hi Experts,

Here I am trying to create offline app. I have used three buttons for add(used collect function ), Save (used savedata function) and load(used loadData function). I referred this documentation -https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-savedata-loaddata. and this video- https://www.youtube.com/watch?v=NwbqdA9j8Ek. Data is getting loaded on click of Load button into gallery. But when I close the app and reopen the app then the record gets invisible and when I click on load button again then the data which I added previously gets loaded into gallery.

I want add data offline and whenever I come online insert that data into CDS.

 

Any help is appreciated!

Thank you.

 

 

 

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    Hi @Anonymous ,

    What is your LoadData and SaveData code - please post as formatted text if possible.

  • Community Power Platform Member Profile Picture
    on at

    Hi @WarrenBelz ,

    Please find my code here-

    Code on Add button- Collect(JourneyColletion,{cre08_name:TextInput2.Text, cre08_companyid:TextInput3.Text,cre08_drid:TextInput4.Text});

    Code on Save button- SaveData(JourneyColletion,"Saveitemstokeep")

    Code on Load button- LoadData(JourneyColletion,"Saveitemstokeep",true)

     

    "JourneyColletion" is my collection name. I have used ClearCollect on  "OnVisible" property of my first screen - ClearCollect(JourneyColletion,Journeys)

     

    Thank you.

     

     

  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    @Anonymous ,

    There is nothing wrong with your code and it should work offline and save those three values to JourneyCollection.

    You have not said what you are doing to write the collection to CDS when online.

     

     

  • Community Power Platform Member Profile Picture
    on at

    Hi @WarrenBelz ,

    Thanks for the response!

    I have used below code on button-

    If(Connection.Connected,
    Patch(Journeys,Defaults(Journeys),{
    cre08_name:TextInput2.Text,cre08_companyid:TextInput3.Text,cre08_driverpmid:TextInput4.Text,cre08_journeystartdateandtime:DatePicker1.SelectedDate
    }),
    Collect(JourneyColletion,{cre08_name:TextInput2.Text, cre08_companyid:TextInput3.Text,cre08_driverpmid:TextInput4.Text,cre08_journeystartdateandtime:DatePicker1.SelectedDate});
    SaveData(JourneyColletion,"Saveitemstokeep")
    );

    and used below code  on App "OnStart" property.- 

    LoadData(JourneyColletion,"Saveitemstokeep",true);
    If(!IsEmpty(JourneyColletion.cre08_name),
    ForAll(JourneyColletion,Patch(Journeys,Defaults(Journeys),{
    cre08_name:cre08_name,cre08_companyid:cre08_companyid,cre08_driverpmid:cre08_driverpmid,cre08_journeystartdateandtime:cre08_journeystartdateandtime
    })

     

    I have tested this offline but my app is not inserting my data into CDS entity when I come online. 
    Do I need add any other steps?

  • Verified answer
    WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    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.

     

     

  • Community Power Platform Member Profile Picture
    on at

    Hi @WarrenBelz ,

     

    Thank you for the beautiful explanation!

  • Community Power Platform Member Profile Picture
    on at

    Hi @WarrenBelz ,
    Need one more help
    Scenario is- I am using scanner through which I am fetching data like this -2f64748a-248e-ea11-a811-000d3ab1893a and using this I want fetch some data and display that.

    Data is like this-
    Name  Surname     ID   
    Ram     dfghj          2f64748a-248e-ea11-a811-000d3ab1893a
    Sham   dfwert        2f64748a-248e-ea11-a811-sdfghjkl345678

    How can I fetch the record (such as Ram as name and dfghj as surname ) having 2f64748a-248e-ea11-a811-000d3ab1893a as ID in OFFLINE mode.
    I have used First(Filter(PopulationMasterCollection, cre08_populationmasterid=GUID(scanValue))) and it is working as expected in online mode but I want that offline.
    Any help is appreciated!

  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    Hi @Anonymous ,

    You would need to collect and save the list that has this ID number and then lookup into this collection.

  • Community Power Platform Member Profile Picture
    on at

    Hi @WarrenBelz ,

    Thanks for the response!

    I got the issue 🙂

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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard