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
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.
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":[]}
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
Problem solved. Mystery not.
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.
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.