NetTalk Central

Author Topic: Adjust a Dictionary LONG field to output as formatted date in API return VIEW  (Read 5319 times)

RichCPT

  • Newbie
  • *
  • Posts: 15
    • View Profile
Is there a dictionary property that can be set on a LONG field in a TABLE, so the field will be output as a formatted date string when used in an API Service returned VIEW?

I have the "Screen Picture" set to "@D2" in the Dictionary for a LONG field in a Table.  I have an API service that returns a VIEW which includes one table with that LONG field, but it always outputs the clarion integer representation of the date value.  It seems to me I saw a NetTalk video where the "Options" tab was used in the Dictionary to add a custom "Property" which would cause output of the field in an NT API service method to be formatted as a date string.  Could someone tell me how to set that or where it is documented or if I am remember things wrong?  Thanks.

-RichCPT

Jane

  • Sr. Member
  • ****
  • Posts: 372
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
You can put in a snippet of code in xml.SaveCurrentFieldToXML or json.FormatValue to format the returned XML or JSON field the way you want.

https://www.capesoft.com/docs/NetTalk11/NetTalkWebServices.htm#FormattingFields

Jane

RichCPT

  • Newbie
  • *
  • Posts: 15
    • View Profile
Thanks Jane.
So, it turns out there is an issue when using jFiles ver 1.81 with auto formatting turned on and a VIEW is output to JSON and field-name case is set to "AsIs".  The template puts in code to format the field based on the dictionary's Display property for the field, but as you can see from the below snippet it doesn't work because of the "lower()" used at the top of the case, but not for the field names.

json.FormatValue                 procedure(String pName, String pValue, *LONG pLiteralType)
  ...
  Case lower(pName)
  of 'Date'
    pLiteralType = json:string
    Return clip(left(p_web.FormatValue(pValue,'@D2',net:ExpandIfNeeded)))
  ...


Setting the template to use "lowercase" field names helps solve that issue.

It seems to me, though, that there is a way to specify the output format of field for the NetTalk Server API's by using a custom option in the dictionary.  That's what I really want to know.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
>> So, it turns out there is an issue when using jFiles ver 1.81 with auto formatting turned on and a VIEW is output to JSON and field-name case is set to "AsIs".

the issue is in NetTalk, not jFiles, but thanks for the report Rich - I've tweaked that for build 11.16

>> It seems to me, though, that there is a way to specify the output format of field for the NetTalk Server API's by using a custom option in the dictionary.  That's what I really want to know.

there isn't a way to do it in the dict, although there is a way to do it in the API itself...
Setting an option in the dict is an intriguing idea, although not one I had considered.

cheers
Bruce