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.
Related
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)
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.)
Can anybody say that if a control for example a button is available more than once, we have to say that the button is available more than once.
Look at below Code sample, which might help:
WinButton button = new WinButton(parent);
button.SearchProperties[WinButton.PropertyNames.Name] = propertyValue;
int buttonCount = button.FindMatchingControls().Count();
if(buttonCount > 1)
//then it means that button is available more than once.
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
On my exchange rate XPage, I want to be able to confirm the value the user has entered using a simple action. Using getComponent, I'm able to get a handle to the localCurrency (combobox) and effectiveDate (inputText that's a date). Those values are then easily displayed in the confirmation dialog. However, the exchangeRate always returns null.
Here's the exchangeRate inputText:
<xp:inputText style="width:75.0px;text-align:right;" id="exchangeRate"
value="#{exchangeRateDoc.exchangeRate}"
readonly="#{javascript:!exchangeRateDoc.isEditable();}"
disabled="#{javascript:!#IsNewDoc();}">
<xp:this.converter>
<xp:convertNumber type="number"></xp:convertNumber>
</xp:this.converter>
</xp:inputText>
...and here's the confirm, which brings in the localCurrency and effectiveDate values without a problem, but always reports exchangeRate as null.
<xp:confirm>
<xp:this.message><![CDATA[#{javascript:var baseText = "Are you sure that you want to set the exchange rate for ";
var effectiveDate = getComponent("effectiveDate").getValue().toString();
var localCurrency = getComponent("localCurrency").getValue();
var exchangeRate = getComponent("exchangeRate").getValue();
return baseText + localCurrency + " to " + exchangeRate + " as of " + effectiveDate + "?"; }]]></xp:this.message>
</xp:confirm>
Where did I go wrong in my code that it cannot get the value of that inputText?
Do localCurrency and effectiveDate pick up values entered in the browser, or values defined last time that area of the page was refreshed to the browser?
You're computing SSJS to pass to a CSJS confirm() message. I would expect it to display values at the last refresh, not values just entered by the user. If you want the latest values, I think you'll need to access them via CSJS.
It's a classic error of confusing client-side with server-side. The values the user has entered on the client side are not accessible on the server-side until they've made it to the server. Since the confirm simple action is available on the server-side actions, you can only access server-side values when using it.
However, as Paul pointed out, the window.confirm method is available on the client-side and one can easily do the confirmation there, accessing the client-side values.
Functioning code for this would be:
<xp:eventHandler event="onclick" submit="true" refreshMode="complete"
immediate="false" save="true" id="eventHandler3">
<xp:this.script><![CDATA[var baseText = "Are you sure that you want to set the exchange rate for ";
var effectiveDate = document.getElementById("#{id:effectiveDate}").value;
var localCurrency = document.getElementById("#{id:localCurrency}").value;
var exchangeRate = document.getElementById("#{id:exchangeRate}").value;
return window.confirm (baseText + localCurrency + " to " + exchangeRate + " as of " + effectiveDate + "?");]]></xp:this.script>
<xp:this.action><![CDATA[#{javascript:exchangeRateDoc.save();
context.redirectToPage("/pro_exchangeRate_view.xsp")}]]></xp:this.action>
</xp:eventHandler>
Many thanks to Paul for pointing out my mistake!
Edit: Make sure that the client-side script returns a value. In my initial version of this script, it just had the window.confirm command, which offers the dialog to the user, but it disregards the response and executes the server-side commands anyway! Oops!