Set default value on metadata field using JS API


(Pheasley) #1

Hi,

 

Is it possible to clear a text metadata field using the JavaScript API? Setting the field to null or empty both result in the metadata field being an empty string, I want it to be cleared (back to (default))

 

I'm using setMetadata() with the enhanced API.

 

Thanks,

 

Paul.


(Bart Banda) #2

Hi Paul, I don't believe so. Would be a nice feature request though. 


(Bart Banda) #3

You could however use a trigger instead, and use the set metadata value action, as that allows you to set it back to the default. 


(Pheasley) #4

Good idea with the trigger, thanks Bart.


(Anthony) #5

I'd vote for the feature request too as I use the JS API a lot to manipulate metadata. But to avoid breaking anything that already sets an empty string value using setMetadata(), it might need to be a new function like clearMetadata(), or  a new optional boolean parameter "TreatEmptyStringAsClear.

 

While I'm talking feature enhancements, I really wish there was an option to use the metadata field name in setMetadata() or setMetadataAllFields() rather than having to pass in the asset ID's. It's always irritating to have to go look them up, and it makes the code really unreadable and hard to spot bugs. Lost count of the number of times I've copy/pasted a bit of code and forgotten to update one or more specific field ID's properly.


(Bart Banda) #6

I'll send the set default metadata via JS API as a feature request, should be an easy one to develop. Will most likely be another parameter in the setMetadata function.

 

The problem with using field name as the metadata target for the JS API, is that it's not unique and safe enough. Not only can someone easily change the field name of a field and stuff up the implementation, but a field name is not unique and different asset types can have the same field name for different reasons, which can also cause confusion. 


(Joel Porgand) #7

While I'm talking feature enhancements, I really wish there was an option to use the metadata field name in setMetadata() or setMetadataAllFields() rather than having to pass in the asset ID's. It's always irritating to have to go look them up, and it makes the code really unreadable and hard to spot bugs. Lost count of the number of times I've copy/pasted a bit of code and forgotten to update one or more specific field ID's properly.

 

If abstract your field ids out into an object so they're not inline in the JS API call that will make your code more readable & help you catch issues.