Welcome to the new Box Support website. Check out all the details here on what’s changed.

Create metadata on file with template

New post

Comments

2 comments

  • BWT
    Metadata customerMetaData = new Metadata(jsonObject);

    The syntax above should not work unless you change the Metadata (JsonObject values)  constructor to public.

     

    My original code was

    Metadata boxMetadata =  new Metadata()
    //For String
    boxMetadata.add("/author", "Author");

    //For Date
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");
    SimpleDateFormat outSdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    Date tempDate = sdf.parse("04/13/2017");
    boxMetadata.add("/datePrinted", outSdf.format(tempDate));

    Metadata.Add() only supports String value and it will only work for String and Date fields but not Number/Float field.  To accomodate for Number/Float field, I have to use the code below.

     

    You don't need the "/" if you are passing jsonObject to the Metadata() constructor. Try this

    final JsonObject jsonObject = new JsonObject();
    //For String
    jsonObject.add("title", "title"); jsonObject.add("author", "author");
    //For Number
    Float tempNumber =Float.parseFloat("10");
    jsonObject.add("amount", tempNumber);
    //For Date
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");
    SimpleDateFormat outSdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    Date tempDate = sdf.parse("04/13/2017");
    jsonObject.add("datePrinted", outSdf.format(tempDate));

    Metadata customerMetaData = new Metadata(jsonObject);

     

    0
    Comment actions Permalink
  • aclark1

     I'm trying to do the exact same thing but NOT use a jsonObject.  Was going the jsonObject route the only way you saw success with creating metadata fields that were of type date?

     

    Thanks!

    0
    Comment actions Permalink

Please sign in to leave a comment.