Subject: RE: Lost in using AJAX
Jen,
If you had probelm in understanding n implementing steps , You should tell .Atleast I can write some pseudo code for u .
Your first issue is to get the selected document handle from web. So, you have couple of ways to achieve the same
a) Enable “Allow selection of document” property of view and use following code to get selected document handle.
var strUIDs=“”;
var Sep=“”;
var count=0;
var chkboxes = document.getElementsByTagName(“input”);
for(i=0;i<chkboxes.length;i++)
{
if(chkboxes.item(i).attributes["type"].value == "checkbox")
{
if (chkboxes.item(i).checked)
{
strUIDs = strUIDs +Sep+chkboxes.item(i).value ;
Sep="~#~";
count=count+1;
}
}
}
if (count>0)
{
alert(strUIDs);
}
else
{
alert("Please select atleast one document to delete");
}
b)You can also write your own HTML code to make checkbox in first column of the view, like :
“<input id="$$SelectDoc_”+@Text(@DocNumber) +“" type=checkbox value=” + @Text(@DocumentUniqueID) + “>”
c)Last way , same as first Enable “Selection of document” property of the view , you can notice domino will generate checkbox with name “$$SelectDoc”. Just u need to take handle of this field and just loop through all the selected checkbox and handle as I have written code above.
Now next , you can see in above code i got all selected check box value into variable “strUIDs”. Now write AJAX function and pass same variable into AJAX. Eg:
var sURL = './YourAgent?OpenAgent';
var sReturn = postCommand(sURL, strUIDs);
You “postcommand” function as follows :
function postCommand(sURL, sParms){
var objHTTP = initXMLHttpRequest();
var sReturn = "";
try{
objHTTP.open("POST", sURL, false);
objHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
objHTTP.send(sParms);
sReturn = objHTTP.responseText;
}catch(e){
if(typeof alertError == "function"){
alertError(e);
}
}
return sReturn;
}
Write an agent which will get all UNID and will fetch details of those UNIDs agent name like “youragent” in above argument.
you agent will look like below:
Print |Content-type:text|
Set nsThisSession = New NotesSession
Set ndbThisDatabase = nsThisSession.CurrentDatabase
Set ndocThisDocument = nsThisSession.DocumentContext
sParmArgs= ndocThisDocument.Request_Content(0)
sParmsData=Split(sParmArgs,"~@~")
strUserFirstName= Cstr(sParmsData(0))
strUserMidName = Cstr(sParmsData(1))
strUserLastName = Cstr(sParmsData(2))
strUserCompanyName= Cstr(sParmsData(3))
strUserMailAddress= Cstr(sParmsData(4))
strUserOfficePhoneNumber= Cstr(sParmsData(5))
strUserHTTPPassword = Cstr(sParmsData(6))
strUserFirstName=Evaluate({@URLDecode("Domino";"} & strUserFirstName & {")})
strUserMidName=Evaluate({@URLDecode("Domino";"} & strUserMidName & {")})
strUserLastName=Evaluate({@URLDecode("Domino";"} & strUserLastName & {")})
strUserCompanyName=Evaluate({@URLDecode("Domino";"} & strUserCompanyName & {")})
strUserMailAddress=Evaluate({@URLDecode("Domino";"} & strUserMailAddress & {")})
strUserOfficePhoneNumber=Evaluate({@URLDecode("Domino";"} & strUserOfficePhoneNumber & {")})
above is my code which do something else , but just u need to get UID, which u passed from AJAX .
use getDocumentByUNID method and get the document handle.
after geting document handle , fetch all individual fields value and return those values into the calling function like :
CompanyName$=personDoc.GetItemValue(“CompanyName”)(0)
MailAddress$=personDoc.GetItemValue("MailAddress")(0)
OfficePhoneNumber$=personDoc.GetItemValue("OfficePhoneNumber")(0)
HTTPPassword$=personDoc.GetItemValue("HTTPPassword")(0)
End If
Print CompanyName$+"~@~"+MailAddress$+"~@~"+OfficePhoneNumber$+"~@~"+HTTPPassword$
You can see the print statement , In AJAX call it wonot print the data rather just return all the values into the calling function.
So, u can get all field values into “sReturn” variable which we used on the top.
Just split all the values bcos we separated all wid “~@~”.
pass all values into the form and compose using JS.
Hope I gave all the things , u just need to arrange …
Still u can contact me if any issues u have
Cheers
Rishi.