calling agent send dialog box to user xpages - dialog

how to send error message to user from agent when using xpages?
Here the detail engine:
1. The xpages contains a button. when the button was clicked then it will call the agent to process the context info
2. On processing the agent, is it possible to send warning message to user (dialog box)? If yes, What command for send it?
Thanks

An agent cannot directly interact with XPages. One method would be to write output to a control document and for XPages to pick up that control document and put the message in a requestScope variable to be displayed on the page.

I agree with Paul. Just adding a small snippet here for you to start:
var agentName:String = "agentName";
var agent:NotesAgent = database.getAgent(agentName);
if (agent != null)
{
var doc:NotesDocument = document1.getDocument() // assuming datasource name is document1
agent.runWithDocumentContext(doc);
/*
In your agent you process a document with particular form and say a unique id of the passed
document context
*/
var v:NotesView = database.getView("warningView"); // For eg. stored in a warning view
var warningDocument:NotesDocument = v.getDocumentByKey(doc.getUniversalID());
// You can process the document according to your needs then ( you can do later step after your dialog is opened)
}
else
{
// throw and error message
}
Hope this helps.

Chintan and Paul are correct. Using the technique described in this article you can capture all print output from an agent and use that in the XPage. However....
This is an excellent opportunity to pay down some technical debt and transform your agent into a bean. If it is well written, it should be easy. If its not, then you clean it up

Related

Alert in view record for Netsuite

I have been trying to get a alert in Netsuite for view mode but can't get it for customer record.
Though when I tried to get the alert for the edit record then I got it but I want it for view.
I tried client script, user event script and also workflow. But all support only for edit. Can I get the alert by any means for the view record option.
Thanks
Gladiator
One workaround that I've done is to add a custom field of type 'Inline HTML' to the customer form. Then during the beforeLoad event you can check if type == 'view' and update the custom field's value with the HTML that is needed to display the alert.
Basically form.setScript used to work with SS1 but there was no (not hacked) API access to Netsuite's alerts
SS2.0 gives nice access to the alert system but it doesn't load in view mode unless you take a supported action (clicking a button)
See this answer for a sample with SS2 that loads your script and shows an integrated alert.
SS2.0 Display Message on Record
Thanks Mike, Michoel and Bknights.
Here is the solution to the problem.
Create an inline html field on the customer form.
Since the field does not store value nlapiSetFieldValue for before load function works absolutely fine.
Below is the snippet of the working code.
function before_load(type)
{
if (type == 'view')
{
var pass_value = "<html><body><script type='text/javascript'>window.alert('Hello World!!!')</script></body></html>";
nlapiSetFieldValue("custentity25", pass_value); //custentity25 is the id of Inline HTML field we created
}
}
Note : The "" used should be different then the one used in the HTML code which is ''. If same are used then there will be an error.
You need to use a User Event Script, and in the before load event, set a Client Script via form.setScript(). In your "injected" Client Script, you can display the alert.

#Mailsend in xpages button

In Client Notes programming there is an action button:
#MailSend(Destinatari;"";"";"Subject";"";"";IncludeDoclink])&
#Command([FileSave])&#Command([FileCloseWindow])
I want to make a similar action in my xpage application which works both in XPiNC and web.
My sendto field is a DjTextarea which can have multiple values.
I tried to create a simple action for my button from xpage: Action: Send Mail. In this way, can I embedded < the IncludeDoclink from Lotus Notes> in the body of the mail? Or I need to write a javascript for this action?
Thanks for your time!
UPDATE: following #Lothar suggestions, my Save & Send button has the following code lines:
if(frmDoc.isNewNote()){
frmDoc.save();
}
var thisdoc = frmDoc.getDocument();
var tempdoc = database.createDocument();
tempdoc.replaceItemValue("Form", "Memo");
tempdoc.replaceItemValue("SendTo", thisdoc.getItemValue("txt_names"));
tempdoc.replaceItemValue("Subject", "subject");
var tempbody:NotesRichtextItem = tempdoc.createRichTextItem("Body");
tempbody.appendText("This is my Mail, click on the doc link below to open the original doc:")
tempbody.addNewLine(2);
tempbody.appendDocLink(thisdoc);
tempdoc.send();
thisdoc.recycle();
tempbody.recycle();
tempdoc.recycle();
Where frmDoc is my doc datasource. I get an error like: NotesRichTextItem.appendDocLink(lotus.domino.local.Document) null - at the appendDoclink line. - the same error I noticed in the #Fredrik useful suggestion too.
I use the HTML email function that can be found in xSnippets when sending emails in xpages.
XSnippet SSJS HTML Mime emails
or
XSnippet email Bean
None of them as an function for attaching a doclink, but you could manually add an url to the document.
Another way is to create the email manually by creating a document is the database
adding a richtextfield called body and a subject and a sendto field.
And adding a doclink to the Body field.
var doc:NotesDocument = database.createDocument();
var My_DocLink_Doc:NotesDocument=database.getDocumentByUNID("UNID_of_Document")
doc.replaceItemValue("form", "Memo");
doc.replaceItemValue("sendTo", "the_emailadress");
doc.replaceItemValue("subject", "an email to you");
var RT:NotesRichTextItem=doc.createRichTextItem("Body")
RT.appendText("This is my Text")
RT.addNewLine()
RT.appendDocLink(My_DocLink_Doc)
doc.send();
There's really not much to add to Fredrik's answer, but I'm afraid you might be looking at the wrong pieces of his solution. I just tested it myself, and it's working just fine, so here's the result, step-by-step:
my xpage is bound to a Notes form named testMail using a document datasource called mailDoc. It is built like this:
Control#1 is a textarea with a multiple separator set to a comma, so that I can enter multiple mail addresses separated by commas. The textarea is bound to a Notes field named SendTo:
<xp:inputTextarea
value="#{mailDoc.SendTo}"
id="sendTo1"
multipleSeparator=",">
</xp:inputTextarea>
Control #2 is a simple EditBox control bound to a Notes field named Subject:
<xp:inputText
value="#{mailDoc.Subject}"
id="subject1">
</xp:inputText>
A button control labelled Save & Send first saves the current document if it is New (i.e. has never been saved before), then performs all the necessary steps to send a doclink for the currently opened doc (button's onclick event); in the following code I'm using these variables:
mailDoc = my datasource object;
thisdoc = the backend doc object that the datasource is bound to;
tempdoc = a temp backend doc object used to be sent via Notes mail:
if(mailDoc.isNewNote()){
mailDoc.save();
}
var thisdoc = mailDoc.getDocument();
var tempdoc = database.createDocument();
tempdoc.replaceItemValue("Form", "Memo");
tempdoc.replaceItemValue("SendTo", thisdoc.getItemValue("SendTo"));
tempdoc.replaceItemValue("Subject", thisdoc.getItemValue("Subject"));
var tempbody:NotesRichtextItem = tempdoc.createRichTextItem("Body");
tempbody.appendText("This is my Mail, click on the doc link below to open the original doc:")
tempbody.addNewLine(2);
tempbody.appendDocLink(thisdoc);
tempdoc.send();
thisdoc.recycle();
tempbody.recycle();
tempdoc.recycle();
Result: the button code sends a mail containing a Notes document link to all the recipients that I previously entered in the SendTo field.
If I set the testMail form's property to use the Xpage in Notes (Defaults >> On Open >> Display Xpage instead >> mailSendTest), then this also works for the XPinc version. And if the recipient then clicks on the doc link the originating document of course opens in XPinc mode as well.
Remark:
I need to save the originating doc at least once otherwise the appended doc link might not be usable for the recipients; could this have been the reason why Fredrik's answer didn't work for you?
Hope this helps. If this is working for you please accept Fredrik's answer.
Update:
Changed some variable names in my code example to clarify things
I simply use these two lines:
var url =
#Left(facesContext.getExternalContext().getRequest().getRequestURL(),"newDocument.xsp")+"newDocument.xsp?documentId="+document1.getDocument().getUniversalID()+"&action=openDocument";
rtitem.appendText(url);
where newDocument.xsp is the form xsp of the document, rtitem is the rich text field of the mail. That will add the whole link to your document.

xpages: compute Confirm Action confirmation text does not work in XPiNC

I'm using Notes/Domino 8.5.3. I've added a button control to an xpage. The button uses a Confirm Action to display a client-side prompt to the user before continuing with the next action defined for the button. When I use static text for the Confirmation Text for the Confirm Action, the confirmation prompt is displayed. However, when I change the Confirmation Text to be computed, and retrieve the text from a profile document, the confirmation prompt it not displayed at all in XPiNC. The confirmation prompt with the computed confirmation text is displayed just fine in a browser. Is there a work-around for this issue with XPiNC?
Following is the code I'm using in the Confirm Action to get the text for the prompt:
var server = database.getServer();
var dbProfile:NotesDocument = database.getProfileDocument("DBProfile", "");
var msg = dbProfile.getItemValueString("ContactsInitUpdatePrompt");
return msg;
To further my comments, this is a work around I use the below code for an app that uses the bootstrap extension library on the web but uses basic functionality with xpinc.
If the values for xPinc are different you could make the confirm action different in the browser and in the client.
if (#ClientType()== "Notes")
{
<action>;
}
else{
<action>;
}
I think that profile documents are a bad idea in xPages though. Having to restart HTTP to get a new value ruins the point I think. Almost better to hard code values at that point. I think you can set application scope to handle the work of profile documents. But then application scope in xpinc is just on the current machine as the server is the client.

How can i get data from another document when i creat a new document on my XPage?

I've start to develop XPage 7 weeks ago, and i have a problem with "getting data".
On my first page i have a view with a lot of documents, and a button who redirect me on a new page, to create a new document. On my first page i can select a document and when i click on the button i put my id document selected on a sessionSCope.
Button script:
var viewPanel=getComponent("viewPanel1");
var docIDArray=viewPanel.getSelectedIds();
var docUID=database.getDocumentByID(docIDArray[0]).getUniversalID();
sessionScope.put("docUID", docUID);
context.redirectToPage("AjoutSuivi");
On my new XPage i want to get some data on my selected document so on clientLoad of the XPage i execute this script:
var docUID = sessionScope.get("docUID");
var doc:NotesDocument = database.getDocumentByUNID(docUID);
getComponent("contactname1").setValue(doc.getItemValueString("ContactName"));
On my database i have a field "ContactName" and on my XPage i have a field contactname1. I have try with "database.getDocumentByID(docUID)" and i'm sure that "database" is the good link of the database.
When i try it, there is nothing on the field contactname1 have u an idea why that's doesn't work ?
So much thank's if you can help me
Yann
PS: sorry for my bad english
Put your code into the event afterPageLoad and it should work (for the execution order of events take a look at XPage Cheat Sheet #1 - The Page Lifecycle).
Y4nn welcome to the XPages club. When you bind a control to a data source it is better to set the value in the data source than in the control. So you write:
document1.getDocument().replaceItemvalue(...)
(picking on a glass now, watch out for correct syntax)

Validation before submitting the Search form generated using filterGrid in JQGrid

I have a search form I generated using the filterGrid option in JqGrid. I want to add a JavaScript logic which is invoked before I submit the Search form. I have added a method which is invoked by the beforeSubmit property for the filterGrid. It goes into the method before submitting, but always submits the form regardless of the value returned. I would like the form to not submit if the javascript returns false.
Have any of you guys implemented anything like this before. Or is there any othe rbetter way to implement this. Any help on this will be really appreciated.
Code:
$("#search").filterGrid("#resultsGrid",
{gridModel:true,gridNames:true,enableSearch:true,
formtype:"vertical",buttonclass:"submitButton",
enableClear:true,beforeSearch:validateDate});
function validateDate(dateDiff) {
if(daysDiff < 0){
return [false,"Message"];
}
} // ??? (commented by Oleg)
return [true,""];
}
There are at least three different ways how searching can be used: Toolbar Searching, Custom Searching which you use and Single field searching or Advanced Searching which share the same code. So one have currently three different implementations of close things.
Only Toolbar Searching has beforeSearch event handler which can return false to stop searching. In case of Custom Searching the value returned by the event handler beforeSearch will not used. Single field searching or Advanced Searching don't call any event handler before searching. In all cases for the searching will set searching filter and the jqGrid parameter search to true and then force grid reloading with the code like
$("#gridId").trigger("reloadGrid",[{page:1}]);
To be able to make any validations and stop reloading of the grid I see no simple way. So I suggest only following.
You can overwrite the standard reloadGrid event handler and chain it. The corresponding code con look like following:
var grid = $("#gridId");
var events = grid.data("events"); // read all events bound to
var originalReloadGrid; // here we will save the original event handle
var skipRefresh = false; // this can be changed by owe validation function
// Verify that one reloadGrid event hanler is set. It is typical sitation
if (events && events.reloadGrid && events.reloadGrid.length === 1) {
originalReloadGrid = events.reloadGrid[0].handler; // save old
grid.unbind('reloadGrid');
var newEvents = grid.data("events");
grid.bind('reloadGrid', function(e,opts) {
if (!skipRefresh && grid[0].p.search) {
originalReloadGrid(e,opts);
}
});
}
Probably I will create later a demo which demonstrate this on an example and place the link to the demo here. Moreover I will try to suggest code changes to jqGrid so, that in all different implementations of searching will be possible to stop serching by returning false by beforeSearch event handle.
UPDATED: OK! I prepared a demo for you. In the demo I use no server components, so it will not really do searching, but you can see the results if the grid will be refreshed and goes to the page 1.
To test the demo you can do following:
type in the "Client" input field a text not starting with 'test' and click "search" button. You receive an alert which simulate the validation dialog.
type in the "Client" input field a text starting with 'test' like test1 and click "search" button. Now the grig will refreshed because the validation will be OK.

Resources