create a user defined template

I want to create a use defined ElektronTimeseriesReportTemplate using REST API,

to change the format for a specific field: Settlement Price

but failed because of ("DecimalPlaces", 9), ("DecimalSeparator", "Period"),("IntegerPlaces", 25)

java code like below:

HttpPost httppost = new HttpPost(urlHost + "/Extractions/ElektronTimeseriesReportTemplates"); 
httppost.addHeader("content-type", "application/json;odata.metadata=minimal");
httppost.addHeader("Authorization", "Token " + sessionToken);
// Note: content fields are specific to each report template type
JSONOrderedObject reportTemplateJSONObject = new JSONOrderedObject()
.put("@odata.type", "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ElektronTimeseriesReportTemplate")
.put("ShowColumnHeaders", true)
.put("CompressionType", "GZip")
.put("Name", reportTemplateName )
.put("Headers", new JSONArray() )
.put("Trailers", new JSONArray() )
.put("ContentFields", new JSONArray()
.put( new JSONObject()
.put("FieldName", "Settlement Price")
.put("Label", "")
.put("Justification", "Center")
.put("WidthStyle", "VariableWidth")
.put("Format", new JSONObject()
.put("@odata.type", "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ContentFieldNumberFormat")

.put("DecimalPlaces", 9)
.put("DecimalSeparator", "Period")
.put("IntegerPlaces", 25)
.put("UseLeadingZero", false)
.put("NegativeSignPosition", "Before")
.put("UseThousandSeparator", false)
.put("UseTrailingZero", false)
))

)
.put("Condition", new JSONOrderedObject()
.put( "StartDate", StartDate + "T00:00:00.000-00:00" )
.put( "EndDate", EndDate + "T00:00:00.000-00:00" ));

Best Answer

  • I think this is related to the order of json object. Currently, the "@odata.type" has to be first element in the object, otherwise some properties will be failed to be loaded. Please change the JSONObject() to JSONOrderedObject() to prevent this issue.

    .put( new JSONOrderedObject()
    .put("FieldName", "Settlement Price")
    .put("Label", "")