Data to Componenet

Hi everbody,

I have a repeating component to list patient data. I want to be able to delete the entire record of that patient if the user presses the trash bin. I can not make the configuration. I can not get the id of the record from anywhere (I use local data for my app). Can you help?

This depends on how you’ve structured your data. If each patient is stored as an object in a local storage instance, then DELETE RECORD is the right choice. The resource name will be the data resource you defined for that object, and the id would be the patient’s id. If you don’t have or know these items, then maybe you need to start with create & read operations before tackling delete.

Since you mentioned a repeating component, your data is more likely a list of objects (one object for each patient). In that case, to delete a patient you can modify the list to remove the object that matches some criteria. For example, if the list of patients is in an app variable called “Patients”, then you could use a SET APP VARIABLE, setting variable name Patients, with assigned value being the formula:

REMOVE_ITEM_BY_KEY(appVars.patients, “id”, pageVars.selectedPatientId)

This will remove the one object from the list that has an ID that matches selectedPatientId. This, of course, requires that your schema includes an id for each patient and that you know that id when you want to delete it. After modifying this list, you would need to be sure to save the results to your local storage by using an UPDATE RECORD block.

@Marty_Flickinger While we’re waiting on him to reply, I have a related Q.

Under what circumstances would you have all Patients loaded into an app variable, vs. making REST calls to show Patients in a list?

In your 1st two paragraphs (of your reply), you mention 2 strategies, neither of which I use or am familiar with:

  1. “If each patient is stored as an object in a local storage instance” - haven’t got there yet - but am wondering what considerations would be to do it this way? My data is in MSSQL - so is this something for that backend (I thought REST API was the way to get to this data, ala Xano) or is this something for GoogleSheets, firebase, etc.?

ok, you contrast this to “local storage”. So if Patients are NOT in local storage, then where are they?
And if in the cloud, then they were fetched when the app started all into a List?
…but then you say to “save the results to your local storage” - so I’m kinda confused.

Again, I’m a ‘real’ developer, not a no-coder. So I’m using REST API to get to my MSSQL data. And I have thought about loading data all into memory (so to speak) so I didn’t have to fetch each record constantly from the db for lists and detail pages.

Since you think Patients could be done this way, what would be the conditions where you would adopt this?
Can you manage 1000 Patients in this Object List? 10,000 ?
Would you load the Patient image too?
Or maybe just a thumbnail into the List?
If the client must be both iPhone and Android, is there a limit imposed by the OS on how big this List can be - and do we know how to calculate the exact storage requirements so I’d know what my Max COUNT of Patients could be?

If 1000 Patients is doable, and you know you’re only in a 400-person facility, then would you definitely adopt this approach?
Is it because its read-only?
Would accessing data be virtually instant? (vs. dependent on network)

To stay with the Patient example… what if I wanted to add notes. The majority of data IS read only, but I have a 500 character Note field in the main record. I may need to add something to this. I’m sure I can ask for the new note text, then POST that to the backend. Is it easy enough to re-GET that one field/record from SQL and update just that field in the List?

ok, sorry, lots of Qs. Skip them if you don’t have time and I’ll post a new thread.

My response to OP was completely based on his statement “I use local data for my app”. In this case, all data create/read/update/delete is handled by modifying local storage records. Working copies in vars, permanent storage in local storage. I have an app I’m working on that does a hybrid of these 2 strategies (master list of things stored as one resource record, then list of items associated with each of these things stored as their own resources). All of this is entirely local (no cloud storage/internet access required for this application).

For your case (REST to back-end service), the “how” is entirely different. But the idea could be the same: local transient copy of data fetched from cloud for user to view. But if your database or records get very large, obviously there may problems of space/speed/traffic that would make you do something more sophisticated than just pulling down a copy of all the data. And my testing with AppGyver has never used any vars with 1000 (or 10,000!) records, so I have no idea how well this approach scales to your application. I would venture a guess that you should not force the app to carry around all that data, but rather do a filtered get from your back-end to obtain just the records the user asks for. Your solution and strategy will be highly dependent on your choice of back-end and how you structure your data there.

One of my data records is about 1000 chars (thats total chars in the JSON stream for 1 object). Could be 1500 depending if product description is longer.
I’m only going to have 300-500 records. Would be interesting to see the time it takes for AG to load those into internal memory structure once the JSON payload is received.

I’m used to Kendo for a UI on web apps - easy filtering. Makes a round trip to the db to filter and get result set. I saw the power up here:

and wonder how that will work as well with 300-500 recs in memory.

Someone on the forum was asking about a book app with static data - this is similar. Would be nice to have filters for 5 of the fields for users to scan those 300-500 recs. I’m excited to see how fast (or slow) this could be.

Ok thank you for all that information but I believe I could not made myself clear.
1 I have a new component (which I designed in the component template editor.)
2 It has mutiple text and paragraphs in it to show
3. It also has some buttons
4. I can populate data on text fields when I use “Repeat with” function
5. But when it comes to delete the record I can not take the record ID to the delete button because in the component editor it asks me "Resource Name " and “Identifier” (as in the picture I sent in my first post
6. The problem is the system does not let me to select my resource (which is an object with a scheme as you guessed) I am adding the picture for this
7. All of those things can be done when :I am not in the COMPONENT EDITOR but not while I am trying to setup a new component.
8. There are things like “Data Resource Adapter” and “Data Variables” in the properties section of the component editor whic I could not find any info on.
So that is the problem that I hope I could explain.

Image where it says the resource is unavailable

The system says this when I am in the component editor and I dont know how to solve

“Data resource and other variable binding types that access the app-level or page-level context are not available in composite component template editor. Instead, you should define an appropriate composite component property, and bind the variable to that property.”

Yeah, composite component internals don’t have direct access to page variables or even app variables. You have to add component properties to do this. For example, to pass the ID value:

  1. Inside your component, click the properties slider
  2. In the Properties tab, add a new property (“ID”). Set the type to “text”
  3. Click back to “View” for component
  4. On the properties for your Delete Record block, click the X and change to Component Properties / Composite Component Internal Property / ID
  5. Now when you exit the template editor, and click on your component, you’ll see it has an “ID” property that needs something bound to it. This value will be connected then to your inner objects as you defined in step 4

In doing this, you are basically creating a “public interface” for the internals of your composite component. This is how your component could be listed in the marketplace and still work for other projects in the future.

Providing a value for the resource name seems a little more complicated. I tried a quick test and I THINK this is what you should do.

  1. Create a Data Resource Adapter under the Data tab
  2. Select arbitrary schema option
  3. Give it a Data resource key of something like “recordResource”
  4. Something similar for Title
  5. I don’t think any of the other options matter for an arbitrary schema
  6. In your Delete Record block, bind the Resource Name to Data Resource / recordResource
  7. Exit template editor, and you’ll now find that your composite object has a property of recordResource that you can bind to your app’s data resources (where you couldn’t access those from within your component directly).

I didn’t fully test this out, but it seemed to be liking it.

Again, I think this is AG’s way of abstracting your composite component so that it’s not critically dependent on things in your app and would work for other people’s apps.

Is there some reference for the Data Resources which I can read? I couldn’t find anything related to this in docs nor am I able to find a Youtube video on this