xPage WebQuerySaveAgent


Run "WebQuerySave" Lotus Script Agent from xPage:

While migrating your old notes database project on new xPage, you might have faced some difficulty to rewrite complex Lotus Script agent logic in xPages Server Side JavaScript language (SSJS) , of course is not a good deal to rewrite complex agent and its bit difficult we know. 

But now no need to worry, xPage has an ability to understand the server side Lotus Script code by doing few simple changes in existing Lotus script code.

And what are those?  
let find it below - you may be aware on this property but how to use?

Below are the simple steps to use lotus script agent on xPage-

Step -1
Open your Lotus Script WebQuerySave agent in script editor.
Find below code which is used to set current webpage document i.e. documentContext and simply remove it, insted of this you need to set current wen document using document note id. 


remove below line- *** Set WebDoc=session.DocumentContext 'Remove this line from your code

REM Webdoc is your webpage document
REM Add below code Lines to your agent

Dim session As New NotesSession 'Object declaration for session 
Dim db as NotesDatabase 'Object declaration for database   
Dim webdoc As NotesDocument 'Object declaration for web document
Dim agent As NotesAgent 'Object declaration for current agent 
Set db=session.Currentdatabase 'Set current database  
Set agent=session.Currentagent 'Set current agent 

'add below line
noteid=agent.Parameterdocid   'Important line-  it returns the 
document note 'Id for the document which we have passed in to the agent for execution i.e. the xPage form document from web page

Set webdoc = db.GetDocumentByID(noteid) ' Important line, its takes       the  document note id to set current webdoc

Setp-2 

Open you xPage and add below code in xPage -Events "postSaveDocument"
remember you have to add javascript code on 'postSaveDocument' only, because on this event xPage becomes loaded successfully in memory

now select "Add Action.."button  and select action list box and then find "Execute Script" and select it.
Select language as "javascript(serverside)" and add below code.


=================================================

var LSAgent=
database.getAgent("your webQuerySave agent name") // it will set the current agent in server memory 
LSAgent.runOnServer(document1.getNotID) // it will pass the current document not id in server memorty that can be utilised in Lotus Script agent

Or you can use below code

agent=database.getAgent("AgentQuerySave")  // it will set the current agent in server memory 
noteid=document1.getDocument().getNoteID() // get your current xPage note ID for document1 
agent.run(noteid) // run agent with selected note id 

*document1 is your form ID which you have added on xPage.

==================================================
Note : The above code will execute in postSaveDocument event only......

Thanks for reading this article, hope you like it, if you have any difficulty please contact us on ‘admin@xpagedomino.com’ or click here to contact us.


No comments :

Post a Comment

Leave A Comment...