NetTalk Central

Author Topic: How to format a field when including it in the output of a NetWebServiceMethod?  (Read 2430 times)

jlavera

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
I'm not sure what I'm doing wrong but cannot achieve what I'm looking for.
I'm getting a range of records by date; the filtering date is working ok, and the date field is in the output. However, the data for the field itself is wrong.

I'm doing a rest server using json, nettalk 11.04.

The answer starts something like this:
{
   "SMSRestApp_ROSTERS_Range_response" : {
      "app_rosters" : [
         {
            "rosterid" : 97525,
            "rostershashmd5" : "24RT0TakMZqJkwOkrDag1g==",
            "startatdate" : 0
         },
         {
            "rosterid" : 241987,
            "rostershashmd5" : "ig0G+KGl6Zo4n01J8OqqrA==",
            "startatdate" : 78481
         },
         {
            "rosterid" : 90338,
            "rostershashmd5" : "BMdQQttOonBPMEPvT2Q99g==",
            "startatdate" : 75646

But you see, the first startdate that is reported 0 is actually the second, the one reported 78481, and so they are displaced one record.
Also, I want it to be formatted @d12. I especified that format everywhere, but still is showing as clarion date.
Should I add hand code? If so, where? Any clue or any other advice?

Kind regards,

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11158
    • View Profile
Hi Jorge,

If you specified the date "everywhere" <g> then I think it should format as @d12.
(assuming you have auto-formatting for the procedure turned on?)

If you don't come right send me an example to look at.

cheers
Bruce

jlavera

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
I think the place where should make most sense to specify the mask should be in the attached window, but there is no entry to specify there. So, may I ask, where is the formatting coming from? In the DCT is as @d12, but it is not taking that. As you can see "auto format" is set to "Yes".

The generated code is like this:
        App_ROSTERSView{prop:order} = AppRosters:StartAtDate
        !
        !MethodReturnViewFilter = 'AppRosters:StartAtDate >=' & deformat(FromDate,@d12) & ' and AppRosters:StartAtDate <= ' & deformat(ToDate,@d12) ; MethodReturnViewSQLFilter =  ; AllowSync=  ; TimeStamp=
        loc:Filter.SetValue('')
        loc:Filter.Cat('AppRosters:StartAtDate >=' & deformat(FromDate,@d12) & ' and AppRosters:StartAtDate <= ' & deformat(ToDate,@d12))
        App_ROSTERSView{prop:filter} = loc:Filter.GetValue()
        jsonResults.RemovePrefix = true
        jsonResults.MaxPrefixLengthInJSON = Len('AppRosters') + 1
        jsonResults.SaveRecords = maxrecords
        jsonResults.SkipRecords = skiprecords
        skippedRecords = jsonResults.SkipRecords
        jsonResults.TagCase = jf:CaseLower
        jsonResults.CascadeDown()
        If p_web.sqlsync then p_web.SqlWait(p_web.SqlName).
        jsonResults.append(App_ROSTERSView,'app_rosters')
        If p_web.sqlsync then p_web.SqlRelease(p_web.SqlName).

I don't realise where AppRosters:StartAtDate  should be formatted. There's even a json.DeformatValue procedure (which has things like Return p_web.DformatDate(pValue,'@d12')), but the json.FormatValue procedure is empty; what should it have there, if anything?

jlavera

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Well, for what it worth, I solved it this way:

json.FormatValue                 procedure(String pName, String pValue, *LONG pLiteralType)
  CODE
 !Added this code.
  Case lower(pName)
  of 'startatdate'
    Return Format(pValue,'@d12')
  End

Now it outputs as I wanted:
      {
            "rosterid" : 90338,
            "rostershashmd5" : "BMdQQttOonBPMEPvT2Q99g==",
            "startatdate" : 20080207
         },
         {
            "rosterid" : 136979,
            "rostershashmd5" : "Wd/MjaTdpiY6Ly2clh2zeQ==",
            "startatdate" : 20130521
         },