Hi
I have been Dec’s excellent guide to XPages to get up to speed. I have a VERY simple question that I cannot find an answer for. In one of the views I have some Server-Side JavaScript that I would like to use to update the status of a document. Here is the code:
var viewPanel=getComponent(“viewPanel1”);
var docIDs=viewPanel.getSelectedIds();
for(i=0 ; i < docIDs.length ; i++){
var docId = docIDs[i];
var doc:NotesDocument = database.getDocumentByID(docId);
// here is my error
doc.status = "5";
doc.checkedBy = session.getUserName();
// end of error
doc.save(true, false)
}
My error that I am trying to use LotusScript notation to set the values of status and checkedBy.
Could somebody please tell me what the correct syntax in JavaScript would be?
Thanking you in advance
Ursus Schneider
Subject: you can use replaceItemValue
You can use:replaceItemValue(name:string, value:Object)
so for your example:
doc.replaceItemValue(“status”, “5”);
Most methods that are available to you are equivalent in syntax to the Notes java methods.
-John
Subject: Another question
Hi John
Thank you very much for the quick answer. That works perfectly :o)
This code is running on the Server as JavaScript. The following line:
doc.ReplaceItemValue (“checkedBy”, session.getUserName());
would now save the Server name and not the users name into the checkedBy field.
How would I get the correct name for the checkedBy field?
Thanks again
Ursus
Subject: you can use @UserName()
They ported over the @UserName() function. You can also use the DirectoryUser class.
Example: context.getUser().getCommonName()
Look at the “XSP” library in the help for details. You can access many of the user’s properties from this class such as roles and group membership.
-John
Subject: Not quite there
Hi John
I gave it a try with context but to no avail :o(
Here’s my code - you see any errors?
Thank you
Ursus
var viewPanel=getComponent(“viewPanel1”);
var docIDs=viewPanel.getSelectedIds();
for(i=0 ; i < docIDs.length ; i++){
var docId = docIDs[i];
var doc:NotesDocument = database.getDocumentByID(docId);
// now set who bestaetigt the record!
var ni:NotesItem = doc.getFirstItem("status");
ni.setValueString("5");
var ni2:NotesItem = doc.getFirstItem("bestaetigtDurch");
ni2.setValueString(context.getUser().getCommonName());
doc.save(true, false)
}