Cumhur Ata
Cumhur Ata

Reputation: 809

confirmation dialog on SSJS

I need to do some ServerSide(SSJS) control in backend then a confirmation dialog should appear in front of the user. i couldn't write the correct code to be worked.

var cVal = getComponent("fieldName").getValue();
if (cVal != "undefined" || cVal != null || cVal != "") {
    var db:NotesDatabase = session.getCurrentDatabase();
    var checkView:NotesView = db.getView("viewname)");
    var checkDoc = checkView.getDocumentByKey(cVal);
    if (checkDoc != null) {
        var scriptCode = "confirm ("
        Are you sure you want to navigate away from this page ? " + "\
        n " + "\
        n " + "
        Press OK to
        continue, or Cancel to stay on the current page.
        "))";
        view.postScript(scriptCode);
    }

/* in this part function should be worked according to user choice. If user click YES the document which is found an backend should be opened. If the user click NO nothing happens. */

Upvotes: 0

Views: 389

Answers (1)

Paul Stephen Withers
Paul Stephen Withers

Reputation: 15739

This is a common mistake when coding applications after moving from client to web. In client, LotusScript can prompt for user interaction, pause, wait for response, then act on that response.

Unless you're performing everything via Client-Side JavaScript, that's not going to work for the web. There are three options.

  1. Instead of using SSJS, put all your code in CSJS using JSON RPC calls to trigger server-side functionality. If you want to continue structuring your applications in this manner, you need to get very familiar with that and it will be much easier to code your CSJS than composing strings.
  2. Prompt before running the SSJS, then give an error message if the document does not exist. This would be my preferred option, if the action is designed to route onwards.
  3. Launch an XPages dialog via SSJS after the rest of your code has run. In that dialog prompt the user and act accordingly. This would be my preferred option if the action is an unexpected by-product of other functionality.

Using an XPages dialog will also allow you to style the dialog consistently with your application rather than being forced to accept browser styling which, in some browsers, can be limited.

Upvotes: 2

Related Questions