I have a field that computes the username in order to save in the document, when I am looking at the xpage it shows my name in the field however after I submit and go into notes looking at the document that was created all values are there except for the names field where my name was to be stored.
I am using the script below to get the name, used in computed. Is there something I am doing wrong that would show my name in the field but not actually save it once submitted?
var name:NotesName = session.createName(@UserName());
name.getAbbreviated();
Subject: data binding
Matthew,
don’t know what type of field you’re using to compute and store your name into. But I assume that you’re using a computed field control.
Point is that in XPages you’ll need to bind your username field to a corresponding Domino field that in turn is part of the form which you then plan to use in your Notes client. I can think of various ways to accomplish that. One solution would be to
-
set up a computed field control which uses simple data binding to the Notes field in question.
-
Since now you no longer can write some extra JavaScript code in the field’s binding you’ll need to write that code someplace else.
-
I’d use the “postNewDocument” event of the corresponding data source. The code would first calculate the user name and then use something like
datasourceName.setValue(“fieldName”, calculatedUserName());
I’m not sure of this is the most elegant way (any comments from the Gurus are welcome), but it does work.
-Lothar
Subject: still not working
Thanks for your response Lothar,
I’m already using the data binding to a computed field in my notes form, that’s part of the reason why I am not sure how come the value won’t store.
I tried your suggestion on using postNewDocument with the code you gave me but I am getting an error 500 after trying it. I used the code below.
document1.setValue(“selectName”, calculatedUserName());
Subject: my mistake, sorry
sorry, I mistyped my javascript code suggestion. Of course there’s no such function as
calculatedUserName()
(don’t know why I put those brackets after what was supposed to be a placeholder…)
What I meant to suggest was something like
var usrname:NotesName = session.createName(@UserName());
dominoDocument1.setValue(“CreatedBy”, usrname.getAbbreviated());
where “dominoDocument1” is the name / id of the datasource and “CreatedBy” is the name of the Domino field that the user name finally will be written and stored to.
Hope it’s working now for you as well…
Subject: Thank you
Thank you so much, that worked perfectly.
Yours got the name just like my computed code accept yours was saved to the document and viewable in notes. I wonder if that’s a bug, it seems to me that if a field is able to grab the value and that field is bound to a field in a form then it should also save.
Thanks again