Desmond Sim
Desmond Sim

Reputation: 211

Xpages java script server side does not update the field in form

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.

Upvotes: 0

Views: 273

Answers (1)

stwissel
stwissel

Reputation: 20404

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.

Upvotes: 2

Related Questions