Clearing MD Entries


#1


I’ve created a MD entries with the blankAppState variable. As in the figure, the format will be productName:[]…

However, when I tried to modify or add another variable in the blankAppState like ‘productName’:[],‘productID:’[], it shows the problem below.

image

I guess is that the MD entry is already exist so it don’t allow me to create another one. Is there anyway to remove or clear the previous entry that I have created so I can add a new one?


#2

You can update an existing entry with window.safeMutableDataMutation.update, or remove entries with window.safeMutableDataMutation.remove


#3

I just tried with window.safeMutableDataMutation.removebut at the window.safeMutableData.applyEntriesMutation part is having this error: error retrieving application state data-100: Core error: Routing client error -> Access denied.

What is the problem?


#4

You might want to check your permissions to make sure you have delete permission.


#5

Ya I revoke the access and re-granted with delete permission and that works!
Thank for being patient with me with my “simple question”. I am a beginner to this network so I have a lot of things have to learn. :sweat::sweat:


#6

Is there a way to clear out all the md entries that i find out from window.safeMutableDataEntries.forEach?


#7

You can populate a mutation transaction object (just like how you are doing it with window.safeMutableDataMutation.remove) as you iterate the entries, and after the iteration finished you can apply the mutation with applyEntriesMutation. Bear in mind that when you remove them they are not deleted from the entries but ts/theirs values are cleared, so you cannot insert a new entry with same key but update it.


#8

The code seems working with no errors but when I look up again to all the MD entries they are still there. Why is they not being remove?


#9

All those function calls you are making are async functions, returning a Promise, you need to properly wait for their resolution either with Promise method .then() or using async / await.


#10

Sorry I editing the post while you replying… I did add await function and it runs now. I also did applyEntriesMutation but the data are not being remove as the second image show.


#11

You’ll need to make sure all the calls use await


#12

I still got some error at some certain part but I manually remove them one by one. Anyway thank you! :grin: