Desmond Sim
Desmond Sim

Reputation: 211

how to create message box on javaScript(server side) using submit button (onclick)

This is my sample script i write.

Task : -To create a pop up message to show user if they haven't register as a member on system.

-User must have name inside the note view "Staff information by name"

-if user have name inside the view, it will write a message to a reviewer, to inform review what they request for.

-if user don't have name in "staff information by name" view, it will pop up a message to told user what to do.

// address book
var db:NotesDatabase = session.getDatabase("websvr/pcs", "names", false);
var vw2:NotesView = db.getView("($VIMPeople)");
var dc2:NotesDocumentCollection = vw2.getAllDocumentsByKey(document1.getItemValue("Name"),true);
var doc2:NotesDocument=dc2.getFirstDocument();

while (doc2!=null){
sname=doc2.getItemValueString('LastName')
doc2=dc2.getNextDocument();
}
// end of address book


//current database
var vw:NotesView = database.getView("Staff Information By Name");
var doc:NotesDocument = vw.getDocumentByKey(sname, true);


    //check whether have setting on reviewer for current user else will be hard code to specific person
    if (doc!=null)
    {
        revname=doc.getItemValueString("Reviewer")
        rev=doc.getItemValueString("ReviewerEmail");

        //set Email
        var maildoc:NotesDocument=database.createDocument();
        var body=maildoc.createMIMEEntity();
        var stream=session.createStream();
        var content="Dear "+revname+",<br></br>"+

        "Please click <a href='http://"+applicationScope.hostname+"/"+(applicationScope.dbfilepath).replace(/(\\)/g, "/")+"/"+
        "RequisitionForm.xsp?databaseName="+applicationScope.serverCN+"!!"+
        applicationScope.dbfilepath+"&documentId="+
        document1.getDocument().getUniversalID()+
        "&action=editDocument'>here</a> to view it if you are in a web browser (eg: Internet Explorer, Mozilla Firefox, Google Chrome etc.)"+
        "<br /><br /><b>OR</b><br /><br />"+
        "<a href='"+document1.getDocument().getNotesURL()+"'>here</a> if you are in the Notes Client. Thank you.";

        stream.writeText(content);
        body.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);
        maildoc.replaceItemValue('Subject', 'Kindly review this '+document1.getItemValueString('Item')+' request by '+document1.getItemValueString('Name')+" on "+I18n.toString(@Today(), 'dd/MM/yyyy'));
        maildoc.send(rev);

        document1.replaceItemValue("TotalCost",document1.getValue("Cost")*document1.getValue("Qty"));
        document1.replaceItemValue("Status","Pending");
        document1.save();
        context.redirectToPage("/MyRequisition.xsp");
    }
else
{
a = 'alert("You do not have access right, please contact admin to register!")' ;
view.postScript(a);
break;
}

The sample script that work on other page :

a = 'alert("The applicant details must be unique!")' ;
b = 'alert("Applicant Details inserted!")' ;

var vw:NotesView = database.getView("Staff information by Name");

var doc:NotesDocument = vw.getDocumentByKey(getComponent("Name").getValue(), true);

if (doc!=null){
view.postScript(a);
break;
}
else
{

var newDoc = database.createDocument();
newDoc.appendItemValue("Form", "Staff Form");
newDoc.appendItemValue("Name", getComponent("Name").getValue());
newDoc.appendItemValue("Designation", getComponent("Designation").getValue());
newDoc.appendItemValue("Department", getComponent("Department").getValue());
newDoc.appendItemValue("Reviewer", getComponent("Reviewer").getValue());
newDoc.appendItemValue("Email", getComponent("Email").getValue());
newDoc.appendItemValue("ReviewerEmail", getComponent("ReviewerEmail").getValue());
newDoc.save();
getComponent("Name").setValue("");
getComponent("Designation").setValue("");
getComponent("Department").setValue("");
getComponent("Reviewer").setValue("");
getComponent("Email").setValue("");
getComponent("ReviewerEmail").setValue("");
view.postScript(b);
}

Upvotes: 0

Views: 6213

Answers (2)

oztur
oztur

Reputation: 365

You can user facesContext and postscript to call JavaScript function on server side.

facesContext.getViewRoot().postScript("alert('"+documentName.getItemValueString("FieldName"));

Upvotes: 0

Frantisek Kossuth
Frantisek Kossuth

Reputation: 3524

postScript() works only with partial refresh. If your code runs in event handler in full refresh mode, your postScript statement will have no effect.

Alternate solution is to use Output script (xp:scriptBlock) component with something like this:

var message = "#{requestScope.message}";
if (message) {
  alert(message);
}

In your SSJS just set your message:

requestScope.message = condition ? "True!" : "False!";

http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.designer.domino.ui.doc%2Fwpd_controls_cref_scriptblock.html

Upvotes: 2

Related Questions