0
votes

case : Update field after select the customer name:

setting : 1 setting view that consist of database path :

DbServer: ServerOne/pcs Directory: office Database name : Customer.nsf

this xpages have a datasource inside, it call "document1"

// get the database path :
var vw3:NotesView=database.getView("Setting Path");
var doc3:NotesDocument=vw3.getFirstDocument();
var server:string = doc3.getItemValueString("DbServer");
var DName:string=doc3.getItemValueString("DbName");
var Directory:string=doc3.getItemValueString("Directory");

var DBName:string= Directory+"\\" +DName;
var db:NotesDatabase = session.getDatabase(server, DBName, false);
var vw:NotesView = db.getView("All Customer");
var doc:NotesDocument=vw.getDocumentByKey(document1.getValue("Customer"),true);

if (doc !=null) {
    document1.setValue("Contact", doc.getItemValueString("Contact"));
    document1.setValue("Telephone", doc.getItemValueString("Phone"));
    document1.setValue("Fax", doc.getItemValueString("Fax"));
    document1.setValue("Email", doc.getItemValueString("Email"));
}

Problem :
The field doesn't update and get the value from "customer" database.

1
Doc.save? And if you have that doc open - the ui won't refresh. The whole xpage? - stwissel
Do you means that the document must be save in order to "refresh" / update the field? - Desmond Sim
I planning to create a New Form. I use value picker to pick on the "customer" database to put inside a edit box call "customer". After that, i use events to write a javascript(serverside) try to update other field. (event i use is (onchange) - Desmond Sim

1 Answers

2
votes

I see a series of problems in your code:

  1. Bind your input field to a scope variable, not to the document itself. It is a search string in the beginning, not part of the new document.

  2. You don't check for the case that the customer wasn't found, so you never know if that was the issue.

  3. I would rather use an URL and resolve instead of server / path / database (but that's a little style

So something like (typed off my head, will contain typos):

var vw3:NotesView=database.getView("Setting Path");
var vwe3 = vw3.getFirstEntry();    
var db = session.resolve(vwe.entries[0]);

var vw:NotesView = db.getView("All Customer");
var doc:NotesDocument=vw.getDocumentByKey(viewScope.customer,true);

if (doc !=null) {
    viewScope.result = doc.getUniversalID();
    document1.setValue("Contact", doc.getItemValueString("Contact"));
    document1.setValue("Telephone", doc.getItemValueString("Phone"));
    document1.setValue("Fax", doc.getItemValueString("Fax"));
    document1.setValue("Email", doc.getItemValueString("Email"));
    doc.recycle()l
} else {
    viewScope.result = "Not found!";
}

// ADD recycle() calls here!!!

Bind a display only field to viewScope.result, so you have a better idea what is happening. Your view must be sorted and indexed by customer name.

Of course you could use the OpenNTF dialog list control instead.