Explicitly set zero in custom metadata with script

Hi all. I have a number of custom metadata properties, which I am trying to populate by means of an external JavaScript. Everything is working well except for zero-value numeric properties.

For example, if my script attempts to set amountpaidbyinsurance to 0, 0.00, or $0.00, DEVONthink essentially discards the value and does not display a value at all in the UI. I’d like to capture an explicit zero here because that’s meaningful and not the same as a blank/null value. I’m setting the values by setting .customMetaData explicitly on the record, as in

  // --- Set Custom Metadata ---
  record.customMetaData = {
    ...record.customMetaData(),
    ...newMetadata, // contains all data extracted or calculated by my script
  };

Is there any way my script can “force” an explicit zero here?

Thanks in advance.

image

Did you try using addCustomMetaData instead of setting the object directly?

I added this and get a “Message not understood error” on the call to app.addCustomMetadata:


  if (Object.hasOwn(newMetadata, 'amountpaidbyinsurance') && newMetadata.amountpaidbyinsurance === 0) {
    app.addCustomMetadata(0.01, {for: 'amountpaidbyinsurance', to: record});
  }

In this test, I was trying 0.01 as a proof of concept, but I get the same error with 0 or 0.00.

The method is called addCustomMetaData with a capital D.

Ah, whoops. I corrected the D. Thanks.

That successfully sets a value for any non-zero value I supply to that method, but it still discards zeroes or zero-like values (0, 0.00, '$0.00’, null, and undefined are the ones I tested). Out of curiosity, I tried NaN, but that is displayed as exactly that, 'NaN', in the UI.

I can get it to display $0.00 in the UI by sending a very small value, as in

app.addCustomMetaData(0.0000000001, {for: 'amountcoveredbyotherinsurance', to: record});

That’s obviously not ideal when what I want is to capture an explicit zero. It’ll probably work for my purposes in a pinch, but it would be nice to do this more precisely.

How is your custom metadata field defined? I think @cgrunenberg is in a better position to demistify that mistery.

Zero values and empty strings are currently stripped to keep the custom metadata store as small as possible.

Ah, that’d do it! Thanks for confirming. I’ll go with a very small value for my needs here and just truncate it in any calculations. Thank you!