Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

srp_json setvalue in an array not working

edited February 2020 in SRP Utilities
This code works fine on my local machine.
Same code running on the server and the fields/arrays - tna_.... are all null when I stringify.
Any thoughts why it might work in my local environment but not on the server?

I have just installed the latest version of srp utilities on the server to be sure it wasn't an out of date thing.

SRP_JSON(ctype, 'NEW', 'ARRAY') SRP_JSON(cdate, 'NEW', 'ARRAY') SRP_JSON(ctime, 'NEW', 'ARRAY') SRP_JSON(clat, 'NEW', 'ARRAY') SRP_JSON(clong, 'NEW', 'ARRAY') SRP_JSON(ctype, 'SETVALUE', 1, "ON") SRP_JSON(ctype, 'SETVALUE', 2, "OFF") SRP_JSON(cdate, 'SETVALUE', 1, ondate) SRP_JSON(cdate, 'SETVALUE', 2, clockdate) SRP_JSON(ctime, 'SETVALUE', 1, ontime) SRP_JSON(ctime, 'SETVALUE', 2, clocktime) SRP_JSON(clat, 'SETVALUE', 1, onlat) SRP_JSON(clat, 'SETVALUE', 2, clocklat) SRP_JSON(clong, 'SETVALUE', 1, onlong) SRP_JSON(clong, 'SETVALUE', 2, clocklong) SRP_JSON(tempBody, 'SET', 'tna_entry_type', ctype) SRP_JSON(tempBody, 'SET', 'tna_act_date', cdate) SRP_JSON(tempBody, 'SET', 'tna_act_time', ctime) SRP_JSON(tempBody, 'SET', 'tna_latitude', clat) SRP_JSON(tempBody, 'SET', 'tna_longitude', clong) SRP_JSON(ctype, 'RELEASE') SRP_JSON(cdate, 'RELEASE') SRP_JSON(ctime, 'RELEASE') SRP_JSON(clat, 'RELEASE') SRP_JSON(clong, 'RELEASE')

each of the variables, ondate, clockdate etc all have valid values.

When I stringify tempbody I end up with

{"tna_entry_type":[],"tna_act_date":[],"tna_act_time":[],"tna_latitude":[],"tna_longitude":[]}

Comments

  • I modified all the "SETVALUE" commands to be the equivalent "ADDVALUE" and got the desired result.
    Problem solved. Mystery not.
  • Mark, it is possible that we broke SetValue along the way. Normally I also use AddValue when appending to Arrays so I never caught this. Can you please confirm the version of SRPUtilities.dll on your workstation where the above code worked?
  • I think the issue was that your local machine had an older utilities than your server because I was able to recreate this bug and fix it in 2.1.1 RC5.

    I figured, while I was in the code, I might as well add some quality of life enhancements. I updated the 'NEW' service to allow initialization of the 'ARRAY' using an OI array, which would simplify your code to this:
    SRP_JSON(ctype, 'NEW', 'ARRAY', 'ON,OFF', ',') SRP_JSON(cdate, 'NEW', 'ARRAY', ondate:@FM:clockdate) SRP_JSON(ctime, 'NEW', 'ARRAY', ontime:@FM:clocktime) SRP_JSON(clat, 'NEW', 'ARRAY', onlat:@FM:clocklat) SRP_JSON(clong, 'NEW', 'ARRAY', onlong:@FM:clocklong) SRP_JSON(tempBody, 'SET', 'tna_entry_type', ctype) SRP_JSON(tempBody, 'SET', 'tna_act_date', cdate) SRP_JSON(tempBody, 'SET', 'tna_act_time', ctime) SRP_JSON(tempBody, 'SET', 'tna_latitude', clat) SRP_JSON(tempBody, 'SET', 'tna_longitude', clong) SRP_JSON(ctype, 'RELEASE') SRP_JSON(cdate, 'RELEASE') SRP_JSON(ctime, 'RELEASE') SRP_JSON(clat, 'RELEASE') SRP_JSON(clong, 'RELEASE')
    I also added two new services: AddValueArray and SetValueArray, which allow you to add or set arrays directly without having to create and release all those handles. So, we can reduce your code further to:
    SRP_JSON(tempBody, 'SETVALUEARRAY', 'tna_entry_type', 'ON,OFF', ',') SRP_JSON(tempBody, 'SETVALUEARRAY', 'tna_act_date', ondate:@FM:clockdate) SRP_JSON(tempBody, 'SETVALUEARRAY', 'tna_act_time', ontime:@FM:clocktime) SRP_JSON(tempBody, 'SETVALUEARRAY', 'tna_latitude', onlat:@FM:clocklat) SRP_JSON(tempBody, 'SETVALUEARRAY', 'tna_longitude', onlong:@FM:clocklong)
    Again, this is only in 2.1.1 RC5 (or 2.1.1 once it's released, which will be soon) or later.
  • For whatever reason I haven't updated my dev version of the utilities to keep in sync with production so yep it's an old one - 1.5.8

    When I look at the live data I see it hasn't actually worked in a few years so it could have broken at any point.

    Kev, I like me some quality of life. Thanks muchly.
Sign In or Register to comment.