Monday 24 March 2008

Converting Web Posted Data into a Notes List collection in an agent

When you use a POST (or for that matter GET) transaction directly to an agent from an AJAX connection call you generally have to do something with the data. I find that converting the arguement name value pairs into a Notes List makes life so much easier. This is how I do it,

' *****************************************
Dim ThisSession as new NotesSession
Dim ThisDoc as NotesDocument
Dim TheParms List as String
' *****************************************
Set ThisDoc = ThisSession.DocumentContext
EvalString = |@URLDecode("Domino";"|+ThisDoc.Request_Content(0)+|")|
RawParms = Evaluate(EvalString)
AmpArray = Split(RawParms(0),"&")
Forall pairs In AmpArray
EquArray = Split(pairs,"=")
TheParms(EquArray(0)) = EquArray(1)
End Forall
' *****************************************

When this code is run you have a Notes List that comprises of all the argument pairs Posted
to to the agent.

Say for example the posted data was :

type=GD&vn=wibble&qi=wobble&dt=01010111

the resultant list would be :

TheParms("type") contains GD
TheParms("vn") contains wibble
TheParms("qi") contains wobble
TheParms("dt") contains 01010111

You can then access any of the arguments passed by name.

If you want to use this with a get you can get rid of the lines

EvalString = |@URLDecode("Domino";"|+ThisDoc.Request_Content(0)+|")|
RawParms = Evaluate(EvalString)
AmpArray = Split(RawParms(0),"&")

and use the Query_String_Decoded cgi variable

AmpArray = Split(ThisDoc.Query_String_Decoded(0),"&")

However remember that unlike the POST the GET string will start with a "&" so your ForAll
will need to test for AmpArray being equal to "" to avoid the first element of the AmpArray.

Steve

2 comments:

Anonymous said...

We are doing the same thing, but passing the JSON string to a web service. The web service processes the data, plus adds the form information and any user access fields required.

Unknown said...

Jeff

Thanks! Good Tip :) I have dabbled my toes in the Web Service pond, but I am not quite up to speed on it yet.. Are you using a notes LS agent or a Java serverlet/agent?

Steve

Disqus for Domi-No-Yes-Maybe