Edit Record Within Smart View

Hi Forest,

I’m trying to create some logic in one of our Smart Views. For context this is an Ember.js smart view that uses Leaflet to draw out multi polygons on a map via JSON data. The polygons are drawn just fine, I simply want to update the JSON data that stores the coordinates on a marker drag event. I looked through the documentation here:

I found ways of fetching, creating and deleting records but not a way to update a record within the component and save. How do we go about doing that?

Thank you in advance

Hi @Arda_Yurdakul,

It’s pretty simple :smiley:, you just need to set the properties you want and then save :wink:

record.set('forest-name', 'myNewName');
record.set('forest-another-property', 'newValue');

await record.save();
1 Like

Hi @vince ,
Thank you for the quick reply. :pray:

Hi again @vince ,

I had marked this topic solved but I ran into a problem with the same topic again.I am having trouble saving changes to a JSON column through an Ember action. Basically we are displaying multipolygons for country areas and we want to add new vertices through a button. However when I push to this JSON array and save it doesn’t seem to stick. (Please ignore the random variables it’s just a test :sweat_smile:). Here’s the code:
image

And here is the console output showing the array’s length that I push into. You can see that it doesn’t save properly:
image

I was able to use the same logic to update and successfully save other fields but not this one.

Hello @Arda_Yurdakul

I don’t know if it is the cause of your issue, but there are several problems with your code:

  1. You are creating a promise with Promise.all waits for all promises created in map, but if you take a look at the callback of the map function, they don’t return the promise returned by save and they don’t even wait for their completion
  2. You passed the result of console.log to then instead of a callback that will execute a console.log

All these problems can be fixed by replacing

record.save()
  .then(console.log(record.get('forest-area')[i][j].length))

by

await record.save()
console.log(record.get('forest-area')[i][j].length)

Hello @GuillaumeGautreau

Thank you. I fixed the problems you mentioned but unfortunately the error persists. The array doesn’t get saved and will print out the same length after await record.save(). Any idea why this might be the case?

Hello @Arda_Yurdakul,

Can you share with us how the field area is declared in your model? I would like to reproduce your issue.

Can you also share the code of your test after modification?

1 Like

Hey @Arda_Yurdakul,

There is some issues with array and json dirty state on Ember. We need to find a workaround but for now what you can do is:

// This will work as the array is not the same as the one before
records.set(`forest-area`, [...coorts]);
1 Like

Hi @GuillaumeGautreau @vince ,

Yes indeed the json field type is the only one I have an issue saving with. For now I managed to implement a workaround by async marker events with Leaflet. Thank you for this workaround as well. It was definitely driving me crazy.

Thank you :pray:

1 Like