view.postscript the connection between backend and frontend JS

Have you ever needed to call a client script after you run some some serverside code.

The answer is view.postScript=”your client side function” this function is available from 8.5.3

The code in view.postScript will be sent back to the browser and executed like onComplete but you can control it from SSJS. Great news or what do you think?

What can I use this for you might ask .

1. Change UI design when the partial refresh has brought up new data

2. If you have a multi window solution use the script to update parent window or close the current

3. Depending of the result do a secondary partial refresh on a case selected panel

If you already used view.postscript, please write a comment about your use case. 

  1. Leon Matthys

    Fredrik, hi.

    I have a button which calls an agent to generate an email:


    document1.save();
    var DocIDParam = "&documentId" + @Left( @Right( context.getHistoryUrl(0), "&documentId" ), "&action" );
    var EmailURL = "http:///testdatabase.nsf/send-email?openagent" ;
    view.postScript("alert('An Email has been sent to the recipient(s).')");
    facesContext.getExternalContext().redirect( EmailURL + DocIDParam+"~FYI" );

    the view.postscript command NEVER APPEARS in the client side.

    The send-email agent runs and leaves my screen blank, not what I want.

    2 things:
    1) Is there a better way to invoke my agent?
    2) will the better way pop up the alert on the client side?

    Thanks
    Leon

    • Fredrik Norling

      Perhaps calling the agent directly in the xpage,
      var ag:NotesAgent=database.getAgent(“Name of Agent”)
      ag.run()
      And if you need to send params to the agent that can be done using a new context document send in on the run param

      You could do an custom alert using XPages DialogBox and call that from the postscript

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.