7
votes

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

1
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

1 Answers

9
votes

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

var doc = document1.getDocument(true);