Changing multiple data in a view - xpages

I need help using Xpages. If there vas a question like this or there is an example can you tell me where to find it.
I have a main page that contains several rows and columns, like this
[Checkbox][Column1][Column2][Column3][Column 4][Column 5]
[Checkbox][Data1][Data2][Data3][Data4][Data5]
[Checkbox][Data1][Data2][Data3][Data4][Data5]
[Checkbox][Data1][Data2][Data3][Data4][Data5]
[Checkbox][Data1][Data2][Data3][Data4][Data5]
[Checkbox][Data1][Data2][Data3][Data4][Data5]
Now Data 5 is a default value and it is Undefined, the only values other that it can be set is to „Do“ or „Do not“. Is there a way to Chek several rows for which i vant to change the value to Do or Do not in Data 5 using combobox and save button, without going into detail view of the data.
For example, i have 30 rows that have Data 5 set to undefined, and i want 10 of them to set to Do. I just chek them in checkbox, select in combobox Do and press Save. So i don't have to endet evry row and edit them one by one.

Adapt the XSnippet Simple "Trash" Folder c/w Selectable Rows & Restore Functionality to your needs.
<xp:comboBox
id="comboBox1"
value="#{viewScope.DoOrDont}">
<xp:selectItem itemLabel="Do"></xp:selectItem>
<xp:selectItem itemLabel="Do not"></xp:selectItem>
</xp:comboBox>
<xp:button id="button4" value="Change selected rows">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
var vp1 = getComponent("viewPanel1");
if(null != vp1){
var dm:com.ibm.xsp.model.domino.DominoViewDataModel = vp1.getDataModel();
if(null != dm){
var idsIter = dm.getSelectedIds();
while(null != idsIter && idsIter.hasNext()){
var id = idsIter.next();
if(null != id){
var doc:NotesDocument = database.getDocumentByID(id);
if(null != doc){
doc.replaceItemValue("yourField", viewScope.DoOrDont);
doc.save();
}
}
}
}
}}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
The example contains a combobox where you can select "Do" or "Do not" and a button which sets this value to all selected documents.

Not sure I got the whole picture of your requirements, but here is one way to do it.
When you "tick" a checkbox, use the server side "onclick" event to set a sessionScope containing the noteid and include any value you want to update the document with. set the refresh id to the checkbox.
For each checkbox the user ticks, a new noteid is added to the sessionScope.
When the user is ready to save the changes using the save button, loop the unids in the sessionScope and update the documents in the background and clear the sessionScope
Using this approach you can also provide a "next" page that show all the documents in the scope and allow the user to confirm the save
you might also want to add a keepalive so the users scope is not discarded

The best way for that is to combine client side and server side code. Here is what I would do in this case :
Add a StyleClass to the checkboxes. In order to do so click on a checkbox, go to all properties and find StyleClass in the list. For example let's put this class name : myCheckboxClass. With this class name you will be able to retrieve easily all the checkboxes checked on the client.
Add also a custom attribute to the checkboxes that contains the unid of the document related to the row. To do so click on a checkbox, go to all properties again and find attr. Add a new attr called for example unid and compute its value to be the unid of the row. This attribute will allow you to know from the client to which document this checkbox is linked to.
Now on your save button, with a client side script, you can really easily get all the documents to modify with the following :
var documentsToUpdate = [];
var checkboxes = document.getElementsByClassName("myCheckboxClass");
for (var i = 0; i < checkboxes.length; i++) {
var checkbox = checkboxes[i];
if (checkbox.checked) {
documentsToUpdate.push[checkbox.getAttribute("unid")];
}
}
// Send the array, in a JSON format, to the server
return XSP.toJson(documentsToUpdate);
Now on your save button, with this time the server side script, retrieve the information from the client, and use the array of unids to change the value you want in the selected documents :
// Get the return value from the client
var jsonDocumentsToUpdate = context.getSubmittedValue();
// Change the JSON into an array
var documentsToUpdate = fromJson(jsonDocumentsToUpdate);
// Go through the array and update the documents
for (var i = 0; i < documentsToUpdate.length; i++) {
var doc:NotesDocument = database.getDocumentByUNID(documentsToUpdate[i]);
// DO YOUR CHANGES
doc.save();
}
Now you have everything to do what you need. You just have to check what the user chose in the combo box and to do the proper changes according to it. I think it's really important to learn this approach combining client side and server side code, that can be apply a lot in Xpages to do what you want quickly.

Related

Delete a field value based on checkbox-Netsuite

I have a requirement where if the user unchecks the checkbox the vale of certain field should be cleared while he saves it.
To be printed is a checkbox
Check # is field.
If the user unchecks the "To be Printed" checkbox the check # field should be clear while he saves the page.
This should be a user event and will be it be after submit funtion?
How do i achieve this?
Here you have two options to deal with your requirement.
1) You can write a Client script as #John mentioned above on his comment and on field change you can clear out those field values which you don't want to save upon your form submission.
2) Write a before submit function and validate the checkbox field value, if it is unchecked then clear out those fields, which you don't want to save.
I would recommend using user event before submit script to set field value as null, as client script may not fire if data entry point is through csv import, suitescript, etc.
if (nlapiGetFieldValue(TO_BE_SUBMITTED_FIELD_ID) == 'F'){
nlapiSetFieldValue('tranid', null);`
}
If you wish, You may write additional client script to disable/clear the field if value of checkbox is set to false, for better UX.
For sequence number I would say, use the below code (I am assuming sequence numbers are pure numbers)
if (nlapiGetFieldValue(TO_BE_SUBMITTED_FIELD_ID) == 'T'){
//search in descending order (use this code in your same before submit script)
var search = nlapiCreateSearch(RECORD_TYPE, ['mainline', 'is', 'T'], new nlobjSearchColumn('tranid').setSort(true));
var results = search.runSearch();
var records = results.getResults(0, 1);
var nextTranId = praseInt(records[0].getFieldValue('tranid'), 10) + 1;
nlapiSetFieldValue(tranid, nextTranId);
}

beforePageLoad failing when a view column is computed

I've got a view control which opens an xpage. When the xpage opens, the beforePageLoad event fires. It checks to see if there are any attachments in a particular field of the document being opened and if there are, it returns list of the filenames. This was working fine. Then, I was asked to change what's displayed in one of the columns of the view. I added a variable to the view control's data section to access the row. I then added some javascript to the column to display the data differently. That worked and it displayed the data as wanted. However, when I now click on the link to open the xpage, when the beforePageLoad event fires, the code that's there now fails. It fails with this error at the starred line:
Script interpreter error, line=9, col=49: 'closureField' is null at
[/Function_ReturnListOfClosureAttachmentNames.jss].ReturnListOfClosureAttachmentNames(CCEB1351591847CB85257E7C005EF68C)
function ReturnListOfClosureAttachmentNames(ltDoc ){
var closureAttachmentFileNames = "";
var thisLT = ltDoc;
var closureField:NotesRichTextItem = thisLT.getFirstItem("closeAttachments");
*>>> var eos:java.util.Vector = closureField.getEmbeddedObjects();<<<
var eosi:java.util.Iterator = eos.iterator();
while (eosi.hasNext()) {
var eo:NotesEmbeddedObject = eosi.next();
closureAttachmentFileNames = closureAttachmentFileNames +","+eo.getName();
}
return closureAttachmentFileNames;
}
I call this function from the beforePageLoad event and pass it currentDocument.getDocument(). I think I might have lost the document context after changing the column display data from 'view column' to 'computed value' but I'm not sure. Any ideas would be appreciated.
thanks!
Clem
Figured it out: When I assigned a variable to the view, when you click on a linked column in that view, it loads the current ViewEntry into the context and not a current document. So I put the unid of the doc from the selected ViewEntry in an application scope variable and returned it to the Document Id property when I open the xPage. I have to now update all my views but there aren't too many luckily. Thanks for working through this with me!
Clem –

Conditional validation not working for one field

I've 4 fields as shown below:
radioGroup1 is required if comboBox2 value and radioGroup4 & radio1 are blank. The validation message is suppose to go away if only one of 3 radio's is selected
If I select radioGroup1 or radio1 and update page, the validation message does not display.
If I select radioGroup4 and update page, the validation message is still displayed.
Here is a screen shot:
Here is a validation code for radioGroup1:
var comboBox2:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox2");
var radio1:com.ibm.xsp.component.xp.XspInputRadio = getComponent("radio1");
var radioGroup4:com.ibm.xsp.component.xp.XspSelectOneRadio = getComponent("radioGroup4");
var radioGroup3:com.ibm.xsp.component.xp.XspSelectOneRadio = getComponent("radioGroup3");
if(comboBox2.getValue()!==''){
if(radioGroup3.getValue()==null){
if(radioGroup4.getValue()==null && radio1.getValueAsString()==''){
return true;
}else {
return false;
}
}
}
In second image there is a computed field capturing value of radioGroup4.
What am I doing wrong? When page is refreshed, radioGroup4.getValue() works in computed field but not in the validation script for radioGroup3.
When any one of 3 radio control selected, the other two are disabled thru script and it is working without any issue.
Resolved this issue as follows:
radioGroup4 was executing script and doing full update in the onChange event. Changed it to onClick event
It need two clicks in the radioGroup4 and required message for radioGroup3 vanishes.
This is not a perfect solution but I've to leave with it until I found perfect one.

Set focus to field using SSJS in Xpages?

I am validating my form using SSJS from a submit button. To display the error to the user I am using the extension library dialog box.
How can I set the focus to the field failing validation, using SSJS?
One thing I might be able to do is use CSJS in the OK button of the dialog box. I close it with the OK button as follows:
var errorField = '#{javascript:viewScope.get("errorField")}';
I tried the following but it does not seem to work.
if (errorField != null && errorField != "")
{
var ef = document.getElementsByName("#{id:" + errorField + "}");
ef.focus();
}
I am setting the scope variable errorField when I do the actual validation.
Yes my bad on the missing colon. Ok tried it out and it doesn't seem to be working for me either when I break up the id expression.
you have a viewScope set to the id of the error field, is it possible for you to set that to :
getComponent('...').getClientId();
if you could do that the you would be able to run:
var errorField = '#{javascript:viewScope.get("errorField")}';
var ef = dojo.byId(errorField);
ef.focus();
that works fine for me.
try using:
var ef = dojo.byId('#{id'+errorField+'}');
ef.focus();
getElementsByName is looking for multiple elements with name="..." and returns an array. you can't set focus to an array of controls.
where as in XPages all controls have unique id's, so using dojo to search for ids will return a single element
Try to set the focus after the partial (or full) refresh is done.
<xp:eventHandler event="onClientLoad" submit="false">
<xp:this.script><![CDATA[ var ef = dojo.byId('#{javascript:getClientId(viewScope.get("errorField"))}');
ef.focus();]]></xp:this.script>
</xp:eventHandler>

Setting value of a Radio Button Group Client Side

I need to set the value of a Radio Button Group that has two possible values. I'm able to accomplish this with SSJS, but having issues setting it via CSJS. Any help is appreciated.
I use something like this:
function setRadioValue(value)
{
var elements = document.getElementsByName ("#{id:radioGroup1}");
for(i=0;i<elements.length;i++) {
if (elements[i].value == value) {
elements[i].checked = true;
}
}
}
Then you can just call setRadioValue("This is teh value of the Radio Button I want to set")
Thanks
You need to get the the server-side generated name of the radio button group using the #{id:} method. Example:
var radioButtonGroup = XSP.getElementById("#{id:radioButtonGroupName}");
You can then use client-side Javascript to manipulate the radioButtonGroup element. I believe you need to loop over the radio buttons in the elements until you find the radio button with the desired value. You can then set its checked value to true.

Resources