Following is a simple demonstration of how documents in memory can be used to communicate between XPages and Agents.The beauty in the following description is that the document in memory is never being saved. That is an awesome stuff that I feel is really helpful for developers in many occations
Create an XPage with a couple of input fields named "boxA" and "boxB" as shown in the following image
Now add a button and label it as you desire and add the following code to it
The code displayed in the above mentioned image does the following,
1. it simply creates a document on the fly named "inMemoryDoc"
2. Handle to an agent present in the backend is obtained
3. The agent is asked to be executed with the inMemoryDoc created in the first step as documentcontext
4. The inMemory document gets updated (not saved) in the backend and the updated values are asked to be displayed on the UI using the getComponent("").setValue() methods.
The code fragment in the agent that resides on the backend is as follows
So as a result when you preview the XPage on the browser and hit the button the out put will be as follows
If you get any errors ensure that the credentials mentioned in the following post are met,
http://ozinisle.blogspot.com/2011/02/agentrunwithdocumentcontextnotesdocumen.html
Hope this helps :)
Share your thoughts and find that its getting better every day. This work of mine helps me realize that.
Tuesday, August 16, 2011
"onbeforeunload" An Illustration/Demo
I recently happened to work with a stuff that required javascript operations to be performed, when a user navigates away from a page or closes it on a browser.
So I ended up discovering the presence of this event "onbeforeunload" for html pages. Though this seems to have some issues with the Opera browser, It seems to work fine with IE, Firefox and Chrome. Haven't tested on safari. The code that helps me do it is quite fascinating as well.
A function named confirmExit() exists that just works like the confirm prompt, which provides with default options asking your opinion on leaving or staying on the same page. The code is as follows
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
</script>
Following is a screen shot of how these pages look on various browsers
So I ended up discovering the presence of this event "onbeforeunload" for html pages. Though this seems to have some issues with the Opera browser, It seems to work fine with IE, Firefox and Chrome. Haven't tested on safari. The code that helps me do it is quite fascinating as well.
A function named confirmExit() exists that just works like the confirm prompt, which provides with default options asking your opinion on leaving or staying on the same page. The code is as follows
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
</script>
Following is a screen shot of how these pages look on various browsers
Hope this helps :)
Wednesday, August 3, 2011
Force UNID on a new document - UNID Hack
Recently I happened to do some thing that required me to force unid on a newly created document. The use cases that I could think about for this kind of scenario are very use ful. Say for example deleting a document by accident may lead to orphan response documents if not taken care of. And if you want to bring them back on association and not screw up things we can use this little tip.
The use is very simple,Following is a lotus script code that will do it for you. Note the way document items are being copied using CopyAllItems command.
Set selDoc=currDB.UnprocessedDocuments.GetFirstDocument
Set newDoc=trgDB.Createdocument
newDoc.UniversalID=selDoc.UniversalID
Call selDoc.CopyAllItems(newDoc)
call newDoc.save(true,false)
And the normal rules apply, a multiple documents can't have same unid with in the same database.
Excersice caution while using this cos, you might just screw up things if you are not cautios. After all we know the importance of the UNID
The use is very simple,Following is a lotus script code that will do it for you. Note the way document items are being copied using CopyAllItems command.
Set selDoc=currDB.UnprocessedDocuments.GetFirstDocument
Set newDoc=trgDB.Createdocument
newDoc.UniversalID=selDoc.UniversalID
Call selDoc.CopyAllItems(newDoc)
call newDoc.save(true,false)
And the normal rules apply, a multiple documents can't have same unid with in the same database.
Excersice caution while using this cos, you might just screw up things if you are not cautios. After all we know the importance of the UNID
Labels:
Lotus Notes,
Lotusscript
Saturday, July 30, 2011
XPages Domino Object Map 8.5.2
I recently happened to come across a page where I was able to find this
XPages Domino Object Map 8.5.2. It reminds me of old times when I used to work with version 7. And I really missed the hirerachy map in later versions though I had them byhearted. This one seems to be pretty similar and is a good one. You get to click on the map to see the details associated with them.
I know many would have known it already, but still there must be people who would seek this. So this is my turn to share my discovery :)
Hope this helps :)
XPages Domino Object Map 8.5.2. It reminds me of old times when I used to work with version 7. And I really missed the hirerachy map in later versions though I had them byhearted. This one seems to be pretty similar and is a good one. You get to click on the map to see the details associated with them.
I know many would have known it already, but still there must be people who would seek this. So this is my turn to share my discovery :)
Hope this helps :)
Wednesday, July 27, 2011
Regular expression to remove all numbers from a string
This is in continuation to my previous post where I posted the code to remove characters that are not digits. This case is vice versa.
var pattern=/\d/g;
var myString="80AlphaDog55";
alert(myString.replace(pattern,""));
The result is AlphaDog
hope this helps :)
var pattern=/\d/g;
var myString="80AlphaDog55";
alert(myString.replace(pattern,""));
The result is AlphaDog
hope this helps :)
Labels:
Javascript,
Regular Expressions
Regular expression to remove all alphabets in a string
Regular expressions are very handly when it comes to working with patterns. In my case working with patterns in javascript. It saves me pile of code that needs to be written in javascript to do pattern based validations.
Following is a simple line of code that helps me to replace all the non digit characters from a string
var pattern=/\D/g
var myStr="80Alpha5Dog5"
alert(myStr.replace(pattern,""))
The answer would be BOSS :)
Hope that helps :)
Following is a simple line of code that helps me to replace all the non digit characters from a string
var pattern=/\D/g
var myStr="80Alpha5Dog5"
alert(myStr.replace(pattern,""))
The answer would be BOSS :)
Hope that helps :)
Labels:
Javascript,
Regular Expressions
Thursday, July 14, 2011
"Automation server can't create object" - Occuring with "ActiveXObject('Word.Application')"
This specific error occurs when your browser does not support ActiveXObjects or it does support ActiveX but the security features configured does not allow it to proceed.
Hence to fix this issue ActiveX controls must be allowed in the browser
Go to Tools -> Internet Options -> Security -> Custom Level and make the following changes under the ActiveX Controls and plug-ins section
1. Enable - Allow prompting for ActiveX controls (optional/probable)
![]()
2. Enable - Download signed ActiveX controls
3. Enable - Initialize and script ActiveX controls not marked as safe for scripting
![]()
Hope this helps :)
Hence to fix this issue ActiveX controls must be allowed in the browser
Go to Tools -> Internet Options -> Security -> Custom Level and make the following changes under the ActiveX Controls and plug-ins section
2. Enable - Download signed ActiveX controls
3. Enable - Initialize and script ActiveX controls not marked as safe for scripting
Hope this helps :)
Labels:
ActiveXObjects,
Javascript
Try catch doesnot catch ActiveXObject errors
I had been thinking about making a post on this for a very long time. Unfortunately for some reason , I kept forgetting about it from time to time. And at last I have even forgot that I faced such an issue in the past until recently.
As per my understanding errors that occur due to automation object creation failures when attempting to create ActiveX Objects can't be handled by try catch block. Instead, one must check it right up front to give the desired error message to the user.
the following is a simple illustration of what i am speaking about,
try{
...
var obj=new ActiveXObject("Blah blah blah"); // suppose error occurs in this statement
...
} catch (activeXError) {
// the error that occured due to active x object creation failure does not get captured here and hence any
//code that you exectute here does not get executed. Rather you can find an abrupt error message in the
//console
}
So in order to handle it, you must check it upfront,
if (window.ActiveXObject) {
... blah blah blah....
} else {
// report error
}
Hope that helps :)
As per my understanding errors that occur due to automation object creation failures when attempting to create ActiveX Objects can't be handled by try catch block. Instead, one must check it right up front to give the desired error message to the user.
the following is a simple illustration of what i am speaking about,
try{
...
var obj=new ActiveXObject("Blah blah blah"); // suppose error occurs in this statement
...
} catch (activeXError) {
// the error that occured due to active x object creation failure does not get captured here and hence any
//code that you exectute here does not get executed. Rather you can find an abrupt error message in the
//console
}
So in order to handle it, you must check it upfront,
if (window.ActiveXObject) {
... blah blah blah....
} else {
// report error
}
Hope that helps :)
Labels:
ActiveXObjects,
Javascript
Thursday, July 7, 2011
Regular Expression to filter HTML Tags
Following is a simple way by which one can filter out the html tags say from ajax responses etc…
normalString=htmlString.replace(/<\/?[^>]+(>
$)/g, "");
inorder to filter out carriage returns one can use
String. replace(/\n/g, "");
normalString=htmlString.replace(/<\/?[^>]+(>
$)/g, "");
inorder to filter out carriage returns one can use
String. replace(/\n/g, "");
AJAX Post Request in Lotus Notes
Following is a short abstract of how you can create AJAX POST request.
One can always find a way to create an XMLHTTPREQUEST and many cross browser solutions are available across the internet. eg w3schools. So if leave the function call in the very first line for you to code.
var mypostrequest=new ajaxRequest()
//handle the response
mypostrequest.onreadystatechange=function(){
if (mypostrequest.readyState==4){
if (mypostrequest.status==200
window.location.href.indexOf("http")==-1){
//handle your response here
}
}
}
//open a post request
mypostrequest.open("POST", “your agent url", true);
mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//sample parameter
Var parameters = “label=value&process=post”
//send in the parameters to be processed in the lotus script agent
mypostrequest.send(parameters);
One can always find a way to create an XMLHTTPREQUEST and many cross browser solutions are available across the internet. eg w3schools. So if leave the function call in the very first line for you to code.
var mypostrequest=new ajaxRequest()
//handle the response
mypostrequest.onreadystatechange=function(){
if (mypostrequest.readyState==4){
if (mypostrequest.status==200
window.location.href.indexOf("http")==-1){
//handle your response here
}
}
}
//open a post request
mypostrequest.open("POST", “your agent url", true);
mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//sample parameter
Var parameters = “label=value&process=post”
//send in the parameters to be processed in the lotus script agent
mypostrequest.send(parameters);
Labels:
AJAX,
Javascript,
Lotus Notes
Subscribe to:
Posts (Atom)




