7

I have a querySaveDocument function for my xPage where I set up some backend fields, including Authors and Readers fields.

var authors = new Array("[AdminEditors]");
var user:String=session.getEffectiveUserName();
authors.push( user );
var authitem:NotesItem = doc.replaceItemValue("z_Authors", authors );
authitem.setAuthors(true);

var readitem:NotesItem = doc.replaceItemValue("z_Readers", "[AdminReaders]" );
readitem.setReaders(true);

I thought doc.replaceItemValue() would return a reference to the NotesItem, but authItem is null.

So how does one create a field on the backend Notes Document using SSJS and get a reference to it?

Thanks,

-- Jeff

Jeff Byrd
  • 163
  • 1
  • 6
  • it works for me. there may be slight difference in exact order of commands. as @Per Henrik Lausten said, use true when getting backend doc (id writes cached updates into datasource). my snippet is slightly different tho: datasource.replaceitemvalue; doc = datasource.getDocument(true); doc.getfirstitem().setAuthors(true) – Frantisek Kossuth Apr 25 '12 at 08:10

1 Answers1

9

Make sure to use getDocument(true) to have the backend document synced with changes made in the frontend document.

var doc = document1.getDocument(true);
Per Henrik Lausten
  • 20,229
  • 3
  • 24
  • 72
  • Thanks for the reply, works like a charm. The admended working code is: doc.replaceItemValue("z_Authors", authors ); // add the authors item doc = currentDocument.getDocument(true); // refresh the doc var authitem:NotesItem = doc.getFirstItem("z_Authors"); // get the item authitem.setAuthors(true); // set it as an authors field doc.replaceItemValue("z_Readers", "[AdminReaders]" ); doc = currentDocument.getDocument(true); var readitem:NotesItem = doc.getFirstItem("z_Readers"); readitem.setReaders(true); -- Jeff – Jeff Byrd Apr 25 '12 at 17:16
  • Perfect, Jeff. Remember to accept the answer then. See this for more details if you are not aware of how this works: http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Per Henrik Lausten Apr 25 '12 at 17:18