Page 1 of 1

Access SVRMOD JSON response

Posted: Fri Oct 13, 2017 9:43 am
by VLNinja70
Hello forum!
I'm currently working on a project where I am taking my website and making it work completely offline.
I have a small amount of data that I want accessed so I am taking advantage of the browsers Local storage.
What I am stuck on right now is storing images that I am retrieving from the server as blobs.

When I take my blob field into a #SYS_WEB.alert box, it shows a blob:... path.
Problem is, that path only exists for the session, so when I go offline that blob doesn't exist anymore.
I noticed that in the response from the server module call, the full blob data:(insanely long string here) information is available.
However, I can't seem to find a way to access that info through RDMLX.
Is there a way I can feed the response I get to a LANSA JSON object so I can get that blob data to store?

Some alternatives I am looking at are doing another call but as a web service or writing a widget (I kinda don't want to do either...)
Here is a snap from chrome's network tool showing the data I am trying to get at:

https://imgur.com/i42ZyJD


Below is the sauce, its all in a web page, no RPs to worry about:

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB)
Define_Com Class(#PRIM_LIST) Name(#List1) Displayposition(1) Left(8) Parent(#COM_OWNER) Tabposition(1) Top(8) Height(689) Width(721) Rowheight(61) Columndrag(True)
Define_Com Class(#PRIM_LIST.Image) Name(#ColumnLTCCUSTIM1) Columnwidth(110) Displayposition(1) Parent(#List1) Source(#LTCCustImage) Columncaption('Logo') Imagesizing(BestFit)
Define_Com Class(#PRIM_LIST.String) Name(#ColumnLTCCUSTNM1) Columnwidth(207) Displayposition(3) Parent(#List1) Source(#LTCCUSTNM)
Define_Com Class(#PRIM_LIST.String) Name(#ColumnLTCCUSTID1) Columnwidth(87) Displayposition(2) Parent(#List1) Source(#LTCCUSTID) Sortonclick(True)
Define_Com Class(#PRIM_LABL) Name(#Label1) Caption('Label1') Displayposition(2) Ellipses(Word) Height(25) Left(8) Parent(#COM_OWNER) Tabposition(2) Tabstop(False) Top(712) Verticalalignment(Center) Width(721)
Define_Com Class(#LTCCUSTID.Visual) Name(#LTCCUSTID) Componentversion(1) Displayposition(3) Left(744) Parent(#COM_OWNER) Tabposition(3) Top(24)
Define_Com Class(#LTCCUSTNM.Visual) Name(#LTCCUSTNM) Componentversion(1) Displayposition(4) Left(744) Parent(#COM_OWNER) Tabposition(4) Top(44)
Define_Com Class(#LTCCUSTS1.Visual) Name(#LTCCUSTS1) Componentversion(1) Displayposition(5) Left(744) Parent(#COM_OWNER) Tabposition(5) Top(64)
Define_Com Class(#LTCCUSTSC.Visual) Name(#LTCCUSTSC) Componentversion(1) Displayposition(6) Left(744) Parent(#COM_OWNER) Tabposition(6) Top(84)
Define_Com Class(#LTCCUSTSS.Visual) Name(#LTCCUSTSS) Displayposition(7) Left(744) Parent(#COM_OWNER) Tabposition(7) Top(104)
Define_Com Class(#LTCCUSTSZ.Visual) Name(#LTCCUSTSZ) Componentversion(1) Displayposition(8) Left(744) Parent(#COM_OWNER) Tabposition(8) Top(127)
Define_Com Class(#ltccustsct.Visual) Name(#ltccustsct) Componentversion(1) Displayposition(9) Height(21) Left(744) Parent(#COM_OWNER) Tabposition(9) Top(147) Usepicklist(False) Width(566)
Define_Com Class(#BigString.Visual) Name(#BigString) Componentversion(1) Displayposition(10) Height(21) Left(770) Parent(#COM_OWNER) Tabposition(10) Top(230) Usepicklist(False) Width(951)

Define_Com Class(#PRIM_WEB.MessageBox) Name(#ErrorMessageBox) Title('LANSA Tools ') Customimage(#LTCOFF_icon)

* Non visual ist of Customer data
Def_List Name(#LTCCUSTList) Fields(#LTCCUSTID #LTCCUSTNM #LTCCUSTPW #LTCCUSTEM #LTCCUSTB1 #LTCCUSTB2 #LTCCUSTBC #LTCCUSTBS #LTCCUSTBZ #LTCCUSTBN #LTCCUSTS1 #LTCCUSTS2 #LTCCUSTSC #LTCCUSTSS #LTCCUSTSZ #ltccustsct #LTCCUSTFL #LTCCUSTST #LTCCUSTEC #LTCCUSTPC #LTCCUSTPP #LTCCUSTPR #LTCCUSTPA #LTCCUSTCL #LTCCUSTCB #LTCDISCCD #LTCCUSTG #LTCCUSTWS #LTCMAPLAT #LTCMAPLON #LTCREPCOD #LTCTRMCDE #LTCMAPLAS #LTCMAPLOS #LTCCUSTSF #LTCCustImage #bigstring) Counter(#ListCount) Type(*Working) Entrys(*Max)
* Grouping of Customer fields
Group_By Name(#LTCCUST) Fields(#LTCCUSTID #LTCCUSTNM #LTCCUSTPW #LTCCUSTEM #LTCCUSTB1 #LTCCUSTB2 #LTCCUSTBC #LTCCUSTBS #LTCCUSTBZ #LTCCUSTBN #LTCCUSTS1 #LTCCUSTS2 #LTCCUSTSC #LTCCUSTSS #LTCCUSTSZ #ltccustsct #LTCCUSTFL #LTCCUSTST #LTCCUSTEC #LTCCUSTPC #LTCCUSTPP #LTCCUSTPR #LTCCUSTPA #LTCCUSTCL #LTCCUSTCB #LTCDISCCD #LTCCUSTG #LTCCUSTWS #LTCMAPLAT #LTCMAPLON #LTCREPCOD #LTCTRMCDE #LTCMAPLAS #LTCMAPLOS #LTCCUSTSF)

Evtroutine Handling(#Com_owner.Initialize)
#COM_OWNER.loadData
Endroutine

Mthroutine Name(loadData)
Define_Com Class(#CustomerServerModuleFLS.FindAll) Name(#getData)
* Check to see if the web page is online
If Cond(#SYS_WEB.Online)
* Purge the current offline storage library
#SYS_WEB.LocalStorage.Clear
* Get the list from the server module
#getData.ExecuteAsync Ltccustlist(#LTCCUSTList)
Else
* Load from the offline storage library
* if it is empty show an error message
If Cond(#SYS_WEB.LocalStorage.ItemCount *GT 0)
* Load the data from local storage
#COM_OWNER.loadfromJSON
Else
* Show an error that you need to be online first to load the inital data
#ErrorMessageBox.Caption := "No offline data available! " + (10).AsUnicodeString + "Establish a connection to load new offline data."
#ErrorMessageBox.Show
Endif
Endif

Evtroutine Handling(#getData.Completed)
* Once the data is back from the server mod, load it into the visual list
Selectlist Named(#LTCCUSTList)
Add_Entry To_List(#List1)
* Call the loadintoJSON method routine to set this list into local storage
#COM_OWNER.loadintoJSON
Endselect
* #SYS_WEB.Alert Caption(#LTCCUSTIM)
Endroutine
Endroutine

Mthroutine Name(loadfromJSON)
Define_Com Class(#PRIM_WEB.Json) Name(#Json)
Define_Com Class(#PRIM_WEB.JsonElement) Name(#CustomerItem) Reference(*DYNAMIC)
For Each(#Item) In(#SYS_WEB.LocalStorage)
#Json := #Item.Value
#CustomerItem <= #Json.RootItem
#LTCCUSTID := #CustomerItem.Item<'ID'>.AsString
#LTCCUSTNM := #CustomerItem.Item<'Name'>.AsString
#LTCCUSTS1 := #CustomerItem.Item<'Ship Address'>.AsString
#LTCCUSTSC := #CustomerItem.Item<'Ship City'>.AsString
#LTCCUSTSS := #CustomerItem.Item<'Ship State'>.AsString
#LTCCUSTSZ := #CustomerItem.Item<'Zip Code'>.AsString
#LTCCUSTPC := #CustomerItem.Item<'Phone Number'>.AsString
#LTCCUSTEM := #CustomerItem.Item<'Email'>.AsString
#LTCCUSTWS := #CustomerItem.Item<'Website'>.AsString
#LTCCUSTCL := #CustomerItem.Item<'Credit Limit'>.AsNumber
#LTCCUSTCB := #CustomerItem.Item<'Current Balance'>.AsNumber
* Guess going the other way I'm not sure how to do that either...
* LTCCUSTIM isn't going to take the blob data and know what to do with it
* So how would I be able to extract the blobs info from my JSON object so LANSA can understand what to do with it?
Add_Entry To_List(#List1)
Endfor
Endroutine

Mthroutine Name(loadintoJSON)
Define_Com Class(#PRIM_WEB.Json) Name(#Json)
Define_Com Class(#PRIM_WEB.JsonObject) Name(#CustomerObject) Reference(*DYNAMIC)
* Create a new JSON Object to the root
#CustomerObject <= #Json.CreateRootObject
* set each key and value to the value of the Field being saved off
#CustomerObject.InsertString Key("ID") String(#LTCCUSTID)
#CustomerObject.InsertString Key("Name") String(#LTCCUSTNM)
#CustomerObject.InsertString Key("Ship Address") String(#LTCCUSTS1)
#CustomerObject.InsertString Key("Ship City") String(#LTCCUSTSC)
#CustomerObject.InsertString Key("Ship State") String(#LTCCUSTSS)
#CustomerObject.InsertString Key("Zip Code") String(#LTCCUSTSZ)
#CustomerObject.InsertString Key("Phone Number") String(#LTCCUSTPC)
#CustomerObject.InsertString Key("Email") String(#LTCCUSTEM)
#CustomerObject.InsertString Key("Website") String(#LTCCUSTWS)
#CustomerObject.InsertNumber Key("Credit Limit") Number(#LTCCUSTCL)
#CustomerObject.InsertNumber Key("Current Balance") Number(#LTCCUSTCB)
* Here is where I am trying to load the BLOB data into my JSON object
* But it keeps using the BLOBs path as in location
* I need to store the actual Blob data
#CustomerObject.InsertString Key("Image") String(#LTCCustImage)

* Create a new local storage entry keyed with the customer ID and for value use the JSON object
#SYS_WEB.LocalStorage.Add Key(#LTCCUSTID) Value(#Json)
* remove all entries from the JSON object so the next iteration can be done
#CustomerObject.RemoveAll
Endroutine

Mthroutine Name(findCustomer)
Define_Com Class(#PRIM_WEB.Json) Name(#Json)
Define_Com Class(#PRIM_WEB.LocalStorageItem) Name(#thing) Reference(*DYNAMIC)
Define_Com Class(#PRIM_WEB.JsonElement) Name(#CustomerItem) Reference(*DYNAMIC)

#thing <= #SYS_WEB.LocalStorage.Item<#LTCCUSTID>
#Json := #thing.Value
#CustomerItem <= #Json.RootItem
#LTCCUSTID := #CustomerItem.Item<'ID'>.AsString
#LTCCUSTNM := #CustomerItem.Item<'Name'>.AsString
#LTCCUSTS1 := #CustomerItem.Item<'Ship Address'>.AsString
#LTCCUSTSC := #CustomerItem.Item<'Ship City'>.AsString
#LTCCUSTSS := #CustomerItem.Item<'Ship State'>.AsString
#LTCCUSTSZ := #CustomerItem.Item<'Zip Code'>.AsString
#LTCCUSTPC := #CustomerItem.Item<'Phone Number'>.AsString
#LTCCUSTEM := #CustomerItem.Item<'Email'>.AsString
#LTCCUSTWS := #CustomerItem.Item<'Website'>.AsString
#LTCCUSTCL := #CustomerItem.Item<'Credit Limit'>.AsNumber
#LTCCUSTCB := #CustomerItem.Item<'Current Balance'>.AsNumber
Endroutine
Evtroutine Handling(#List1.ItemClick)
* #COM_OWNER.findCustomer
Endroutine
End_Com
Thank you!!! :D