I need to create a button in Lotus Notes mail stationary which will insert a text and then the button is deleted from the message.
In the button I have:
res := #Prompt([OkCancelList]; "Is it OK?"; "Select result"; " ";"OK":"Failed":"");
#If(res ="OK";
#Command([EditGotoField]; "Body") + #Command([EditInsertText]; "Everything is fine);
#Command([EditGotoField]; "Body") + #Command([EditInsertText]; "Not so good mate"));
This part works fine, but I am not sure how to delete the button after click. Usually works #Command([EditClear]) but not in this case when I use #Command([EditGoToField]) in the formula.
I suppose i need to use GoToField again with the correct button identifier and then run EditClear, but I do not know where to find it, or if there is another way to do it... Ideas?
Thank you.
Assuming you have the button in field Body and nothing else that have to remain
then change your code to:
#Command([EditGotoField]; "Body");
#Command([EditSelectAll]);
res := #Prompt([OkCancelList]; "Is it OK?"; "Select result"; " ";"OK":"Failed":"");
#If(res ="OK";
#Command([EditInsertText]; "Everything is fine");
#Command([EditInsertText]; "Not so good mate"));
It selects the content of Body (including button) and replaces it by the new text.
Assuming your document is (or could be put into) edit mode, you could still have the button, but have the button in it's own paragraph (or table cell) with a hide-when formula of of MySpecialButtonPressed!="", and then include the line
FIELD MySpecialButtonPressed := #Now;
in the button code.
(Edit: changed test from =1 to !="", then changed the set value from 1 to #Now because Notes doesn't store Boolean values. Unless you're sending out millions of these, the cost of using dates instead of numbers less than the benefit of having more specific information in case you need it.)
Related
I'm trying to show an email pop up window with an attached report. I want the email fields in the popup window to be populated with the attached report's mail settings - similar to what happens when you click the "Send" button when running the report directly. I'm trying to do this in a PXAction method.
I've got it mostly done but, I'm having a problem if the Mail Settings have a formula in them. For instance if the Subject is set to "=[table].[field]" I get "=[table].[field]" in the Subject box for my email popup window instead of the value of table.field.
Any ideas on how to get the values of the Mail Settings fields in the report instead of the verbatim text?
TIA!
Here's what worked for me. I'm sure there's a way to dispense with the code that removes the "=" but, this got what I needed.
protected string GleanMailSetting(Report report, ReportNode reportNode, string settingText)
{
if ((string.IsNullOrEmpty(settingText)) || (!settingText.StartsWith("=")))
return settingText;
string trimmedText = settingText.TrimStart(new char[] { '=' });
PX.Common.Parser.ExpressionNode node = Reports.Parser.ReportExprParser.Parse(trimmedText, report);
node.Bind(report.DataSource);
return (string)node.Eval(reportNode.DataItem);
}
I'm running into a bit of a problem, but I feel so close to solving it. I have a text file with Usernames and Passwords separated with a pipe:
;info.txt
user1|pass1
user2|pass2
user3|pass3
user4|pass4
user5|pass5
user6|pass6
user7|pass7
user8|pass8
user9|pass9
user10|pass10
and here's the code:
Gui, -SysMenu
Gui, Add, Button, , Log in
getUsers()
Gui, Add, Button, , Exit
Gui, Show
Return
getUsers()
{
userList := ""
loop
{
FileReadLine, line, info.txt, %A_Index%
if ErrorLevel
Break
getUsers := StrSplit(line, "|")
userList .= getUsers[1] "|"
}
Gui, Add, ListBox, h100 vChoice, %userList%
}
ButtonLogin:
MsgBox, You chose %Choice%.
Gui, Submit, NoHide
Return
ButtonExit:
ExitApp
Return
I used StrSplit() to separate the User from Pass and then delimit the Users to get them into proper format for the ListBox. Everything loads just fine, but when I select one from the list and hit "Log in," the first one doesn't give me any result then the correct results are delayed by one. Example:
Click user1 > You chose .
Click user5 > you chose user1.
Click user3 > you chose user5.
Also, if anyone has a better way of doing this, please let me know.
Ah, I figured it out. It was a problem with:
ButtonLogin:
MsgBox, You chose %Choice%.
Gui, Submit, NoHide
Return
The MsgBox was happening BEFORE Submit was going through. Fixed:
ButtonLogin:
Gui, Submit, NoHide
MsgBox, You chose %Choice%.
Return
I have an xpage with a data view control, that has show checkbox and show header checkbox enabled. I want to be able to provide confirmation with a count of selected documents to the user when they click the submit button.
Example
"Are you sure you want to submit x number of documents?"
My confirm action returns 0 regardless of how many documents I select. What am I doing wrong?
<xp:confirm>
<xp:this.message><![CDATA[#{javascript:var dataView1:com.ibm.xsp.extlib.component.data.UIDataView = getComponent("dataView1");
var val = dataView1.getSelectedIds();
var len = val.length;
return "Are you sure you want to submit " + len + " number of documents?";
}]]></xp:this.message>
</xp:confirm>
The immediate problem that you're running into is that the confirmation message is most likely being computed as the button is rendered the first time - which is to say, when no documents are checked.
Even beyond that, though, the getSelectedIds method is tricky: the selected documents are cleared after each request, so something that would do a request to the server to get the selected ID count would also have the side effect of clearing out the selections.
What may be the way to do here is to do the check client-side with something like this:
<xp:eventHandler ...>
<!-- other action stuff here -->
<xp:this.script><![CDATA[
var count = dojo.query("tbody input[type='checkbox']:checked", dojo.byId("#{id:yourDataViewId}")).length;
return XSP.confirm("Are you sure you want to submit " + count + " document" + (count == 1 ? "" : "s") + "?");
]]></xp:this.script>
</xp:eventHandler>
The Dojo query in there will search for all checked checkboxes inside the body part of the data view (to exclude the header checkbox), restricted to within the specific data view you want to search for. The XSP.confirm client-side method is the same idea as the <xp:confirm/> simple action, and returning the value from it will cancel the submit if the user says no.
I would like to create a button to search my mail's Inbox view for emails which contain a unique string found in the subject field of the selected document. For this, I have created the following button formula. This correctly retrieves the unique string but the search itself does not work.
SearchStringLeftPart := #Left( Subject; "] [");
SearchString := #RightBack( SearchStringLeftPart; "[");
#SetViewInfo([SetViewFilter];SearchString;Subject;0;0)
Please can someone advise if #SetViewInfo can be used for this purpose & if so what is wrong with the formula. Otherwise how else can I achieve the task using a button formula?
Unfortunately, you can't accomplish that with #SetViewInfo.
But, in combination with a short agent you can show only those documents in view which have current document's unique Subject substring in their Subject field.
Create a formula agent "SelectSubjectSearch" with
target "All documents in view"
option "Selects documents in view"
formula
SELECT #Contains(#LowerCase(Subject); #LowerCase(#Environment("SubjectSearch")))
Create a formula button which
writes the search string into environment variable "SubjectSearch"
selects the option "View / Show / Selected Only" in menu
calls the agent "SelectSubjectSearch"
Button code:
SearchStringLeftPart := #Left( Subject; "] [");
SearchString := #RightBack( SearchStringLeftPart; "[");
#SetEnvironment("SubjectSearch"; SearchString);
#Command([ViewShowOnlySelected]);
#Command([ViewShowOnlyUnread]);
#Command([ViewShowOnlyUnread]);
#Command([ViewShowOnlySelected]);
#Command([RunAgent]; "SelectSubjectSearch")
The tricky part is the "View / Show / Selected Only" selection. As [ViewShowOnlySelected] just toggles between "Select Only" and not "Select Only" and you don't know which status currently is set we have to call a double [ViewShowOnlyUnread] which resets [ViewShowOnlySelected] to not "Select Only". The first [ViewShowOnlySelected] sets the information bar to "You are seeing: the item you selected" and the second [ViewShowOnlySelected] does set for sure "Select Only".
Is the subject exposed in the first (sorted) column of the view?
IIRC, SetViewInfo only filter the view on the first column, which alse must be sorted.
Update: Did not refresh the page after I got back from lunch, so did not see that there already was a correct answer.
Create a search view with first column sorted by subject and use view.getAllDocumentsByKey(...)to get the documenta you search
At first, there's a rich text field in the form that has a text inputted already (for this scenario - "hello world"). I have placed the cursor just after the letter "o" from "hello". I have a button that will open up a dialog box with one text field and I was wondering how would you be able to insert the text from that field from the dialog box at the current position of the cursor in the rich text field.
So far the code I have is:
Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim s As New NotesSession
Dim db As NotesDatabase
Set db = s.currentdatabase
Dim docFill As New notesdocument(db)
Call workspace.DialogBox _
( "Test", True, True, False, False, _
False, False, "Test Insert text at current position in rich text field", docFill, True, False, True )
Dim string1 As String
string1 = docFill.sampleText1(0)
Dim rts As NotesRichTextStyle
Set rts = s.CreateRichTextStyle
End Subs
End Sub
Let's say I entered "stackoverflow" in sampleText1 text field. After clicking ok then it will be inserted at the position of the cursor in the rich text field. So the result will be "hellostackoverflow world".
Also just an additional question. Let's say I also wanted the text to be in color red or a different font so I would be using notesrichtextstyle class etc to design it. How would you be able to insert the rich text at the position of the cursor in the rich text fiel if that would be the case?
You can insert text at current cursor position with the help of the clipboard. Just let the user insert text in a dialog box, select the text after clicking "OK", copy it and then paste it at the current cursor position in RichText field back in your form.
To accomplish that, create an action "Insert text" in your form's action bar with the LotusScript code
Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
If workspace.DialogBox _
("Dlg", True, True, False, True, _
True, False, "Test insert text", doc, True, False, True ) Then
uidoc.Paste
End If
End Sub
Actions in action bars have the advantage that they don't change the cursor position in document on click event. So, the cursor still remains on current position e.g in RichText field clicking on an action button.
Then, create a form "Dlg" for DialogBox with a Text or RichText field "Text". Add the following formula code to form's Postrecalc event (it's executed on "OK" button click):
#Command([EditGotoField]; "Text");
#Command([EditSelectAll]);
#Command([EditCopy])
You have a lot of options with the copy-paste-approach to put content into clipboard:
Create a text in backend and put it direct into clipboard
Create a RichText item in a temp document with all content and style options you can think of, open the document in UI, copy the RichText item content to clipboard and close document without saving
Let users create their text snippet in documents. Let them choose one of it clicking on "Insert text" button - just open the selected document, copy the content to clipboard and close it.
The first problem is that when you click the action button, you will lose focus of the rich text field, and therefor there is no way to know where the cursor was.
I would also suggest that you don't use the extended notation like this:
string1 = docFill.sampleText1(0)
Use the GetItemValue method of the NotesDocument class instead (for several reasons, including performance and future-proofing your code.
If you just want to have the user enter some text, why not use the InputBox function?
Finally, there is not an easy way to insert text in the middle of a rich text. It is much easier to perform a replace of a specific text string in a rich text field. I once created a Lotusscript class to perform mailmerge (create letters based on a template and a form letter with field names and commands), you can find it here: http://blog.texasswede.com/code-mail-mergeform-letters-in-lotuscript/
Perhaps that can help you some. But it has to be done in the backend, you can't do much rich text work in the frontend, unless you use Midas LSX frpn Ben Langhinrichs (http://www.geniisoft.com). I think he got some UI functionality.
But your biggest issue will be the first problem, how to trigger the code without losing focus of the rich text field. I don't see a good solution there. You may want to rethink your design/approach.
If you use a button in the Action Bar then the focus will remain with the rich text field. You can then use uidoc.InsertText("") to insert the text at the current position of the cursor.
You could use...
call uidoc.InsertText( docFill.sampleText1(0) )