Doing lstItem.rating = -1; should work. I believe your problem is doing lstItem.beginUpdate(). Doing this is not necessary for individual track items. The documentation says "Events are not called when in update state", so you might not have seen the rating change in the UI because the it was in that specific state.
I haven't used beginUpdate()/endUpdate() on tracklists myself, so I can't say for certain what the use case of it is. I don't believe you need to worry about using that method, however. Just use commitAsync() either on the individual tracks or the tracklist after you're done to commit the metadata changes.
P.S. I see that the rating property isn't present on the API docs; Adding it now.
Data scientist, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Yes; you need to asynchronously wait for the list to load via whenLoaded(). I wrote some extra documentation on it and it should be up on the API docs site soon. In the meantime:
Tracklist class (list of Tracks). In most cases, when you request a new Tracklist (for example, with uitools.getSelectedTracklist() or playlist.getTracklist()), the list will be returned before it has been populated with its contents. To resolve this, you must asynchronously wait for it to be loaded. You can do this either with Promise.then() or with async/await:
// Method 1
var list = uitools.getSelectedTracklist();
list.whenLoaded()
.then(function () {
// do your operations on the list
});
// Method 2
async function myFunc() {
var list = uitools.getSelectedTracklist();
await list.whenLoaded();
// do your operations on the list
}
myFunc();
if you change your function definition to async function clearFields(){ and add await list.whenLoaded(); after let list = uitools.getSelectedTracklist();, it'll work.
Data scientist, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Data scientist, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Just in case anyone else runs into this. I am doing mass updates to my collection. Doing method one will work for a selection of 1000 songs or less. Method two seems to have an unlimited amount.
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
Since you've already done all the work for it, maybe some would appreciate if you made a "Clear All Fields" addon.
Edit tags > Clear all fields; perhaps the icon could be "warning"; and make sure to make a confirmation prompt. "Are you sure you want to clear ALL METADATA on %s tracks?" (You can do this with the messageDlg global method; check the wiki for details on how to use it). I'd also make the default button "no"/"cancel", just to be safe.
Data scientist, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.