Suitescript 2.0 Get Button on a sublist - netsuite

I have an older Suitescript 1.0 user event script where on the BeforeLoad I change a label on a button in a sublist. (note this is a button on the sublist not on the main header of the form
In order to do that I did something like this:
function changePackageContentsButtonLabel(type, form, request)
{
var mySublist = form.getSubList('recmachcustrecord_tst_my_sublist');
if(mySublist != null)
{
var NewButton = mySublist .getButton('newrecrecmachcustrecord_tst_my_sublist');
if(NewButton != null)
{
NewButton .setLabel('New Label Text');
}
}
}
that worked fine in that i could find the button based on a call to the sublist.getButton
In 2.0 I was wondering how to do that.
I had thought i would call the getButton that is based off the context.form but it does not seem to find the button in that case. And though there are methods to addButton on a sublist, there does not appear to be a getButton on it. I know i could use JQuery but that may be a bit more brittle it seems.

In the Netsuite help section search for
SuiteScript 1.0 to SuiteScript 2.0 API Map
After you get the button object, use label property to get or set a value for the button label.
var myButton = form.getButton({
id : 'buttonid'
});
myButton.label = "New Label Text"

I ended up having to put the logic I wanted into a client script and called it off of the pageInit. What I had to do was use native javascript and locate the button (by document.ElementById() and when i got that element I was able to change the value. This was not the desired way but it seems that 2.0 does not allow you to locate a button on a sublist like 1.0 did.

Related

TestFx - How to test validation dialogs with no ids

I have an application with grid of records and button insert. After clicking insert, there is a form, where you fill in data and click Ok for adding new record to the grid. After clicking Ok, there is validation which fires dialog with error informations, if any of the text fields do not match validation rules. Is there any posible way to test text on the dialog with textFx, if the dialog has no id?
This is an example for Alert based dialog:
In your test:
alert_dialog_has_header_and_content(
"Removing 'Almaty' location", "Are you sure to remove this record?");
In you helper test class:
public void alert_dialog_has_header_and_content(final String expectedHeader, final String expectedContent) {
final javafx.stage.Stage actualAlertDialog = getTopModalStage();
assertNotNull(actualAlertDialog);
final DialogPane dialogPane = (DialogPane) actualAlertDialog.getScene().getRoot();
assertEquals(expectedHeader, dialogPane.getHeaderText());
assertEquals(expectedContent, dialogPane.getContentText());
}
private javafx.stage.Stage getTopModalStage() {
// Get a list of windows but ordered from top[0] to bottom[n] ones.
// It is needed to get the first found modal window.
final List<Window> allWindows = new ArrayList<>(robot.robotContext().getWindowFinder().listWindows());
Collections.reverse(allWindows);
return (javafx.stage.Stage) allWindows
.stream()
.filter(window -> window instanceof javafx.stage.Stage)
.filter(window -> ((javafx.stage.Stage) window).getModality() == Modality.APPLICATION_MODAL)
.findFirst()
.orElse(null);
}
I know this issue is a little old and probably got fixed, but for documentation purpose in case someone else look for a fix for an issue alike, I see dialog.getDialogPane() in Dialog documentation, which would help lookup for specific controls inside the pane. So further on #plaidshirt query, we could retrieve buttons and input fields with:
dialog.getDialogPane().lookupAll()
Then narrow that down to buttons and input fields for example.

SharePoint Online - Show/display column in default view

I am adding a site column into a document library default view and want it to be visible/shown when you click onto the list itself. However, I am unsure on how to do this. The code I have so far
// Get the view (this is the default view)
Microsoft.SharePoint.Client.View v = Employeecvlist.GetViewByName("All Documents");
// Load it up
clientContext.Load(v, x => x.ViewFields);
clientContext.ExecuteQuery();
// Get the field I want to add to the view
Microsoft.SharePoint.Client.Field name =
Employeecvlist.Fields.GetByInternalNameOrTitle("Name");
clientContext.Load(name);
clientContext.ExecuteQuery();
// Add this field to the view !! Nothing else in the view object to allow to make it visible by default !!
v.ViewFields.Add(name.InternalName);
// Finally, update the view
v.Update();
If you look at the image file below, I basically want to be able to check the "display" checkbox to true for the above field.
Can someone point me into the right direction?
Thanks
You need to perform clientContext.ExecuteQuery() again to persist the changes. Also, there's no need to do it twice to load your objects, load everything you need and then get it from the server:
//Put following line in the using section
using Microsoft.SharePoint.Client;
//Your code
View v = Employeecvlist.GetViewByName("All Documents");
Field name = Employeecvlist.Fields.GetByInternalNameOrTitle("Name");
clientContext.Load(v, x => x.ViewFields);
clientContext.Load(name);
v.ViewFields.Add(name.InternalName);
v.Update();
clientContext.ExecuteQuery();

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 –

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