Page 1 of 1

PRIM_MD.Edit to CLOB

Posted: Thu May 12, 2022 2:26 am
by jyoung
It's been a long time since I have done any LANSA work or posted here. :D
It's coming back, but I am having trouble getting a CLOB field to work with a PRIM_MD.Edit.

We have a table defined that contains a CLOB field to store a JSON object.

I am trying to create a UI that will allow us to edit that JSON in a PRIM_MD.Edit field, however when go to set the field, I get a "Expression (type CLOB ) is not compatible with expression (type unicode string)" error.

How do I get the contents from a PRIM_MD.Edit into a CLOB field so that I can save it?

Thanks!
Joe

Re: PRIM_MD.Edit to CLOB

Posted: Fri May 13, 2022 2:30 am
by Dino
Hi Joe

There is a nice example on how to display a json file, is the web page called xDemoWebJsonViewer
you may want to use an approach similar to that if you are planning to edit json text...
jsonedit2.png
jsonedit2.png (36.36 KiB) Viewed 13826 times
If you want to read the json content of a clob field and moved it to a edit value, I would do something like this.. just an idea, there maybe many different ways to do it:

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Theme(#SYS_THEME<MaterialDesignBlue>)

Define_Com Class(#PRIM_MD.Edit) Name(#Edit) Appearance(TextFieldArea) Caption('See your JSON Code in this Edit field') DisplayPosition(1) Height(355) Left(72) MultiLine(True) Parent(#COM_OWNER) TabPosition(1) Top(104) Width(672) ThemeDrawStyle('LightTitle')
Define_Com Class(#PRIM_WEB.FilePicker) Name(#FilePicker1) Caption('First Click here and select a json file and receive it as CLOB ') DisplayPosition(2) Ellipses(Word) Height(41) Left(72) Parent(#COM_OWNER) TabPosition(2) TabStop(False) Top(40) VerticalAlignment(Center) Width(249) ThemeDrawStyle('DarkAccent')

Evtroutine Handling(#FilePicker1.FileSelected) File(#STD_CLOB)
#STD_BLOB := #STD_CLOB.Blob
#COM_OWNER.ReadJSON STD_STRNG(#STD_BLOB)
Endroutine

Mthroutine Name(ReadJSON)
Define_Map For(*Input) Class(#STD_STRNG)
Define_Com Class(#Prim_Web.HttpRequest) Name(#JSONRequest)
Define_Com Class(#PRIM_WEB.json) Name(#Json)

#JSONRequest.Url := #STD_STRNG
#JSONRequest.ExecuteAsync

Evtroutine Handling(#JSONRequest.Completed)
Define_Com Class(#STD_INT) Name(#HttpStatus)

#HttpStatus := #JSONRequest.Response.StatusCode

#Json := #JSONRequest.Response.Content
#Edit.Value := #Json
Endroutine
Endroutine
End_Com
jsonedit1.png
jsonedit1.png (126.24 KiB) Viewed 13826 times

Re: PRIM_MD.Edit to CLOB

Posted: Fri May 13, 2022 7:02 am
by jyoung
Thanks Dino, I did not realize there was a JSON sample out there, will have to check it out.
I got it resolved, albeit not with a CLOB.

I was using a CLOB because I thought it was the only way to generate a VARCHAR(MAX). All of the STD_* text based fields where to small, I think STD_STRNG is 512. I created a new field (type String length 65535) and found that, that too generates a VARCHAR(MAX).
That size should be more than adequate to handle our needs and we don't have to worry about the other issues with CLOBs like dealing with Filenames, not being able to edit in VL Web, etc.

Thanks!
Joe