Subject: RE: Problem : Encoding-Decoding scheme in Domino Web Application
I am really obliged that you want to see my code.
This is my code, in which I am facing problem.
saveRequestorProfile is a java script function, which calls an agent using AJAX. It has 4 parameters; last two parameter (i.e. strLabelName & strFieldValue) can have value as per the selection of language.
function saveRequestorProfile(strDBUrl, boolSetProfile, strLabelsName, strFieldValue)
{
try
{
//generate url to call the agent and passed status in the query string
var url = strDBUrl+"/processRequestorInfo?OpenAgent&sid=" + Math.random();
// make the request content to process
var strRequestContent = "pg=PRCESSREQINFO&setProfile="+boolSetProfile +"&lblNames="+ strLabelsName + "&fldValues=" + strFieldValue;
//var strRequestContent = encodeURIComponent(strRequestContent);
//get the XMLHttp Object for specific browser
objHTTP = GetXmlHttpObject()
//Ajax coding
objHTTP.open("Post", url, true);
objHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
objHTTP.send(strRequestContent);
objHTTP.onreadystatechange = function()
{
//Check if ready state if completed
if(objHTTP.readyState == 4)
{
//Check if status is OK
if (objHTTP.status==200)
{
var strResponseText = objHTTP.responseText;
if(strResponseText ==0)
{
strResponseText = "Done;” }
}
}
}
return true;
}
catch(excep)
{
alert('Common JS Library : Function :: saveRequestorProfile - Error : ' + excep.description);
return false;
}
}
Agent processRequestorInfo
Sub Initialize
%REM
Purpose : 1. if user selects the save as my default option then save information in profile document
2. Validate the form as per process step document
3. Then redirect to the next page i.e. service selection page
Author : Developer 3, Ideafarms
Date : Nov 12, 2007
Version : 1.0
%END REM
Print |Content-type:text|
On Error Goto errorHandler
'Set error flag to false assuming there is no error
objErr.errFlag=False
'variable declaration
Dim docCurrent As NotesDocument
Dim docLogStatus As NotesDocument
Dim strLoggedinUser As String
Dim strStatusLog As String
Dim strRequestContent As String
Dim strTemp As String
Dim intPosition As Integer
Dim boolStatus As Boolean
Dim strpgName As String
Dim strProfileStatus As String
Dim varLblNames As Variant
Dim varFldvalues As Variant
'Instanciate the current session and database
Call IntialiseProc
'If there is an error then exit without further processing
If objErr.errFlag=True Then
Goto cleanExit
End If
'Instanciate the notes object
'Get the current document handle using document context
Set docCurrent = currSession.DocumentContext
If docCurrent Is Nothing Then
'Force the error "current document does not exists"
objErr.DisplayMsg=False
Error 4002, "Current document not initialised by currentSession'"
End If
'create Log document
Set docLogStatus = New NotesDocument(dbCurrent)
docLogStatus.FORM = "frmStatusLog"
strStatusLog = "Agent Name :: processRequestorInfo : Started at: " & Now() & Chr(13)
'Write Agent activity
strStatusLog = strStatusLog + "Step 1: Retrieving request content . . ." & Chr(13)
'get the request contenet send by the calling
strRequestContent = docCurrent.REQUEST_CONTENT(0)
‘ I have tried to decode the strRequestContent here, using
‘strRequestContent = Evaluate(|@URLDecode(“Domino”;”|+strRequestContent +|”)|)
' extract the value from the request content
boolStatus = extractValue(strRequestContent,strpgName, strProfileStatus, varLblNames, varFldValues)
If boolStatus =False Then
'Force the error "current document does not exists"
objErr.DisplayMsg=False
strStatusLog = strStatusLog + " - : Error while retrieving values from request content . . ." & Chr(13)
Error 4002, "'Error while retrieving values from request content"
End If
strStatusLog = strStatusLog + " - : Values retrieved from request content . . ." & Chr(13)
'Check if status is true then store the all information in profie document
strStatusLog = strStatusLog + "Step 2 : Checking status of profile setting option. . ." & Chr(13)
If strProfileStatus="true" Then
' get all the logged in user name and store all the information in the profile document;
strLoggedinUser = docCurrent.REMOTE_USER(0)
strStatusLog = strStatusLog + " - : Status of profile setting option is true" & Chr(13)
strStatusLog = strStatusLog + " - : Setting the requestor's information" & Chr(13)
boolStatus = setRequestorProfile("RequestorInfo",strLoggedinUser, varFldValues)
If boolStatus =False Then
'Force the error "current document does not exists"
objErr.DisplayMsg=False
strStatusLog = strStatusLog + " - : Error while setting the values in profile document . . ." & Chr(13)
Error 4002, "Error while setting the values in profile document"
End If
strStatusLog = strStatusLog + " - : Requestor's information stored in profile document . . ." & Chr(13)
Else
strStatusLog = strStatusLog + " - : Status of profile setting option is false" & Chr(13)
End If
strStatusLog =strStatusLog & "Agent Name :: processRequestorInfo : Stopped at: " & Now() & Chr(13)
Print "0"
cleanExit:
If Not docLogStatus Is Nothing Then
Call docLogStatus.ReplaceItemValue("Body", strStatusLog)
Call docLogStatus.Save(True, False)
End If
objErr.DisplayMsg=True
Exit Sub
errorHandler:
Call objErr.PostError (Err, Erl, "processRequestorInfo :: Agent ","",Nothing,objErr.CreateLogDoc)
Resume cleanExit
End Sub
Related function which is used in the above procedure.
Function extractValue(strRequestContent, strpgName, strProfileStatus, varLblNames, varFldValues) As Boolean
%REM
Purpose : To extract the values from the request content and store into variables
Author : Developer3, Ideafarms
Date : Nov 13,2007
version : 1.0
%END REM
Dim intPosition As Integer
Dim strLblNames As String
Dim strFldValues As String
On Error Goto errorHandler
'Set error flag to false assuming there is no error
objErr.errFlag=False
'Assuming that there is no error and function returns true
extractValue = True
'Extracting the parameter passed by calling
intPosition = Instr(strRequestContent, "&")
strpgName=Mid(strRequestContent,1,intPosition-1)
strRequestContent = Mid(strRequestContent,intPosition+1)
intPosition = Instr(strRequestContent, "&")
strProfileStatus = Mid(strRequestContent,1, intPosition - 1)
strRequestContent = Mid(strRequestContent,intPosition+1)
intPosition = Instr(strRequestContent, "&")
strLblNames = Mid(strRequestContent,1, intPosition - 1)
strRequestContent = Mid(strRequestContent,intPosition+1)
strFldValues = strRequestContent
'Extracting the pgname from the strpgName
intPosition = Instr(strpgName, "=")
strpgName = Mid(strpgName,intPosition+1)
'Extracting the profile status from the strProfileStatus
intPosition = Instr(strProfileStatus, "=")
strProfileStatus = Mid(strProfileStatus,intPosition+1)
'Extracting the lable's name from the strLblNames
intPosition = Instr(strLblNames, "=")
strLblNames = Mid(strLblNames,intPosition+1)
varLblNames = Split(strLblNames,"|")
'Extracting the field's value from the strfldValues
intPosition = Instr(strFldValues, "=")
strFldValues = Mid(strFldValues,intPosition+1)
varFldValues = Split(strFldValues,"|")
'Return the status
extractValue = True
cleanExit:
objErr.DisplayMsg=True
Exit Function
errorHandler:
Call objErr.PostError (Err, Erl, "processRequestorInfo :: extractValue ","",Nothing,objErr.CreateLogDoc)
extractValue = False
Resume cleanExit
End Function
Function setRequestorProfile(strDocName,strUserName, varFldValue) As Boolean
%REM
Purpose : To set the fields value in profile document
Author : Developer3, Ideafarms
Date : Nov 13,2007
version : 1.0
%END REM
On Error Goto errorHandler
Dim docRequestorProfile As NotesDocument
'Set error flag to false assuming there is no error
objErr.errFlag=False
'Assuming that there is no error and function returns true
setRequestorProfile = True
'Instanciate the current session and database
Call IntialiseProc
'If there is an error then exit without further processing
If objErr.errFlag=True Then
Goto cleanExit
End If
'Instanciate the notes object
'get the profile document or create new if does not exists
Set docRequestorProfile = dbCurrent.GetProfileDocument(strDocName, strUserName)
'set the values
docRequestorProfile.fldDivision = varFldValue(0)
docRequestorProfile.fldCompany = varFldValue(1)
docRequestorProfile.fldCountry = varFldValue(2)
docRequestorProfile.fldLocation = varFldValue(3)
docRequestorProfile.fldProcessCategory = varFldValue(4)
docRequestorProfile.fldRequestorName = varFldValue(5)
docRequestorProfile.fldRequestorPhone = varFldValue(6)
docRequestorProfile.fldRequestorEmail = varFldValue(7)
docRequestorProfile.fldCCName = varFldValue(8)
docRequestorProfile.fldCCPhone = varFldValue(9)
docRequestorProfile.fldCCEmail = varFldValue(10)
docRequestorProfile.fldPCType = varFldValue(11)
docRequestorProfile.fldPCAssetNo = varFldValue(12)
'save the document
Call docRequestorProfile.save(False,False)
setRequestorProfile = True
cleanExit:
objErr.DisplayMsg=True
Exit Function
errorHandler:
Call objErr.PostError (Err, Erl, "processRequestorInfo :: setRequestorProfile ","",Nothing,objErr.CreateLogDoc)
setRequestorProfile = False
Resume cleanExit
End Function
Public Sub IntialiseProc
%REM
Purpose: to initialize variables for current session, database
Author: Developer 4
Date: Nov 13, 2007
Version: 1.0
%END REM
On Error Goto errorHandler
'Set error flag to false assuming there is no error
objErr.errFlag=False
If currSession Is Nothing Then
Set currSession = New NotesSession
End If
If dbCurrent Is Nothing Then
Set dbCurrent = currsession.CurrentDatabase
End If
cleanExit:
Exit Sub
errorHandler:
Call objErr.PostError (Err, Erl, "Common :: Script Library ", "",Nothing,objErr.CreateLogDoc)
Resume cleanExit
End Sub
Thanks
Ashish