How to perform a custom search using a button formula - lotus-notes

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

Related

How to Check value of combo-box (selected items) in the formula for a button (Visible property)

We have a PowerApps form with several fields that must be completed before the form can be submitted to the Sharepoint List.
We can't make them required or mandatory on the Content-Type and List because we want the users to be able tosave their data, and come back to it to edit it before Submitting...
So we need to disable/hide the Submit button until these fields are completed by the user.
In our Submit Button control we are using a formula to control the Visibility property of the button, or it's container which is the footer.
So we have tried this kind of thing:
If(
And(
TitleField.Text <> "",DescOfInitiativeField.Text <> "", DateRaisedField.SelectedDate <> Date(
1900,
01,
01
),
Not IsEmpty(PersonalDataChoiceField.SelectedItems.Value),
Not IsEmpty(SpecialCatChoiceField.SelectedItems.Value),
Not IsEmpty(ChildrensDataChoiceField.SelectedItems.Value),
Not IsEmpty(CriminalChoiceDataField),
Not IsEmpty(SourcesOfDataChoiceField.SelectedItems.Value),
but we are not having any luck..
So what's the correct way to go about this? How can we test that at least one of the options in each of our combo-box fields is selected?
I don't know why you add .Value after .Selecteditems
If(IsEmpty(ComboBox.SelectedItems),false,true)
It returns false when nothing is selected
Try something like this in your Visible function of your button:
If(IsBlank(TitleField.Text) Or IsBlank(DescOfInitiativeField.Text)
Or DateRaisedField.SelectedDate = Date(1900,01,01)
Or IsEmpty(PersonalDataChoiceField.SelectedItems)
Or IsEmpty(SpecialCatChoiceField.SelectedItems)
Or IsEmpty(ChildrensDataChoiceField.SelectedItems)
Or IsBlank(CriminalChoiceDataField)
Or IsEmpty(SourcesOfDataChoiceField.SelectedItems), false, true)

Can I use a string as a name in Visual Basic to change an objects properties?

My Idea is not too hard. I have a button, a string called "progname", a TextBox and three Progressbars.
When I enter a number into the TextBox and press the button, the following code run's through.
Dim progname As String
progname = "Progressbar" & TextBox1.Text
Now I have a string called "progname" with relevant value.For an example "Progressbar2".
What I want to achieve is write something like:
progname.Value += 1
Which can't be done, as "Value" is not a Member of "String". How can I do this?
Overall what I want, is to be able to select one of the three progressbars by typing one of the numbers 1-3 into the TextBox and then change that ones porperties.
Yes you can.
A basic example is this, which searches your form for controls with the name matching your string. It then changes the type to a ProgressBar so you can access all the methods ..
Dim progbar As ProgressBar = CType(Me.Controls.Find(progName, False)(0), ProgressBar)
progbar.Value += 1

Capybara how to test for the disabled option in a dropdown list

I am new to Capybara and am trying to write a test where the default option in a dropdown list will change depending on the link the user clicks on in the preceding page. e.g. click on link1, then link1 will be the default option.
I found online someone said to test for the disabled option in a dropdown with the following, but I still can't get it to work.
Then /^"([^"]*)" should be selected for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
with_scope(selector) do
field_labeled(field).find(:xpath, ".//option[#selected = 'selected'][text() = '#{value}']").should be_present
end
end
Based on your description I'm assuming you mean the selected option rather than the disabled option. To do that in Capybara would be
expect(page).to have_select('id, name, placeholder or label text of select', selected: 'text of selected option')
Using that in your cucumber step with the possibility of scoping would then become
Then /^"([^"]*)" should be selected for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
within(selector) do
expect(page).to have_select(field, selected: value)
end
end
which you would call something like.
Then "California" should be selected for "State" within "#user_profile"
If you did really want to check for a disabled option in a select you could do it like
select = find(:select, 'id, name, placeholder or label text of select')
expect(select).to have_selector(:option, 'text of disabled option', disabled: true)
If you want to test if you have the option disabled.
Find the number of elements that disable that area. With the command
"size".
If the result is 1 or 0, you can type this command.
Example:
And(/^All segments in this area need to be subject to the product (\d+) see it$/) do
area=find_by_id('temelGostergeler')
number=area.all("div#urunTab.caption[style='display: none;']").size
print "All of "
expect(number).to eq 0
if
number==1
number="No product"
else
number="There are product"
end
p number
end
You can synchronize with the expect command if you want.

Lotus Notes - button automatic delete after running formula

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.)

How to insert text and possible rich text as well at the current position of the cursor in a rich text field in Lotus Script?

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) )

Resources