How to get number of options in Combo Box in SSJS? - xpages

I've tried getComponent("ComboBoxID").getChildCount() but that appears to not return the correct number. Anyone know if there is a method I can use? Or maybe a function needs to be created?
EDIT - And is there a way to loop through the options and get the values like in CSJS?:
for (var i = 1; i < comboBox.options.length; i++){
pmtPlan = comboBox.options[i].value;
...

Maybe this XSnippet can help:
http://openntf.org/XSnippets.nsf/snippet.xsp?id=get-selectable-values-of-a-component
Instead of printing the selectable value(s) you have to count them.
Hope this helps
Sven

Related

document.createTextNode not working :/

So i am making this program where i need to create an ordered list with lots of list elements inside. This is the code:
for(i = 0; i < numbers.length; i++) {
document.createElement("ls").appendChild(document.createTextNode(eval(numbers[i])));
document.getElementById("list").appendChild(document.createElement("ls"));
}
It only creates the list elements, it doesn't put the text nodes anywhere in the html document. :/
Does anyone know why this happens and how to fix it? Would really help me out.
Instead of adding the "ls" element you've created on the first row to the "list" element, you're creating a new (empty) one and adding it.
Change it to:
var ls = document.createElement("ls").appendChild(document.createTextNode(eval(numbers[i])));
document.getElementById("list").appendChild(ls);

Elasticsearch - Using groovy script within function_score and access field payload

I am trying to understand what is the best way to access the payload while using groovy script.
I want to do something like this:
sum = 0;
categories = doc['category'].values;
for (category in categories){
sum += category.payload
}
return sum;
Edit:
Thanks to #Val and #Lee H I got to this point where I can actually access the payloads. But the suggested solution was to use _index which is not what I am looking for, _index give access to statistics in the scope of the index, and not for a specific document.
I want to go over every document, and take its payload and multiply it with some constant lets say.
when doing this: _index['category'].get('term', _PAYLOADS) I will get a list of all payloads of "term", which will is not what I am looking for.
So is there a way to access a field payload from the scope of a document?
Check out the documentation for
term positions and payloads
it shows an example accessing the payloads for a field
Copying the last example here:
Example: sums up all payloads for the term foo.
termInfo = _index['my_field'].get('foo',_PAYLOADS);
score = 0;
for (pos in termInfo) {
score = score + pos.payloadAsInt(0);
}
return score;
You can achieve this using advanced scripting and the _index context variable.
And Groovy is here to help with a nice one-liner:
return _index['category'].get('term', _PAYLOADS).sum {it.payloadAsInt(0)}

How to Remove the addPreSearch Filter

I am trying to remove the PreSearch filer and my code is as below. How can I achieve the same?
Xrm.Page.getControl("productid").removePreSearch(function () {
Object
});
Xrm.Page.getControl("productid").addPreSearch(function () {
fetchxml2();
});
function fetchxml2() {
var fetchXml1 = "<filter type='and'>"
fetchXml1 += "<condition attribute='productid' operator='in' >";
for (var i = 0; i < Itemid.length; i++) {
fetchXml1 += "<value>" + Itemid[i] + "</value>";
}
fetchXml1 += "</condition>";
fetchXml1 += "</filter>";
Xrm.Page.getControl("productid").addCustomFilter(fetchXml1);
//Xrm.Page.getControl("productid").removePreSearch(fetchXml1);
};
In order to be able to remove the handler via removePreSearch, avoid using an anonymous function by creating a named function and using that in both addPreSearch and removePreSearch:
function preSearchHandler(){
fetchxml2();
}
Xrm.Page.getControl("productid").removePreSearch(preSearchHandler);
Xrm.Page.getControl("productid").addPreSearch(preSearchHandler);
Just wanted to add this to the discussion:
If you, say, have three different custom filters on a lookup field, the functionality will stack when you apply a new filter.
For example, if you have an option set that calls addPreSearch() on the field, if you select all three different options, you will have all three filters applied to the field simultaneously.
say the option set has three options of [option A, option B, option C],
the corresponding functions are, for simplicity [filterA, filterB, filterC],
on the change event of the option set, for each filter that you apply, simply remove the other two (in this case).
if (optionSet == 810500000) {//option A
Xrm.Page.getControl('lookup').addPreSearch(filterA);
Xrm.Page.getControl('lookup').removePreSearch(filterB);
Xrm.Page.getControl('lookup').removePreSearch(filterC);
}
else if (optionSet == 810500001) {//option B
Xrm.Page.getControl('lookup').addPreSearch(filterB);
Xrm.Page.getControl('lookup').removePreSearch(filterA);
Xrm.Page.getControl('lookup').removePreSearch(filterC);
}//so on and so forth
I hope this helps someone out, I was able to apply custom filters to a lookup based on four distinct selections and remove the "stackable" filters by addition and removal in this manner. It's a little ugly, but, hey, it works. At the end of the day, sometimes the most elegant solution is to just win, win win win win.
If you need more context (fetchXml) and such, I can post that, too...but it doesn't really go along with the point I was trying to make. These filters can be applied simultaneously! That's the main idea I wanted to convey here.

Wildcard for hitTestObject ActionScript3 show Instance Name

I have movieClips namely rec1, rec2, rec3, rec4...
Then, I would addChild another movieclip(circle_mc) to those rec MovieClips.
I want to use the hitTestObject... Something like this:
circle_mc.hitTestObject(this["rec" + numStringTarget])
If I specify number on the numStringTarget variable, I can only attach to one of the "rec" movieclips. What I want is the capability of circle_mc to be added on any "rec" movieclips. Is there any way to use wildcard? Or any way to solve it?
I want the code to become like this:
circle_mc.hitTestObject(contains String "rec") then addChild..
I hope someone can solve it or just give me some helpful links to read about. Thanks in advance.
I do not want to set all these statements this way:
circle_mc.hitTestObject(rec1);
circle_mc.hitTestObject(rec2);
circle_mc.hitTestObject(rec3);
circle_mc.hitTestObject(rec4);
what if I have a hundreds or thousands... I want to test if the movieclip, as long as it has word "rec" on its instance name, it will be tested.
Or it could be in another situation. My circle_mc is draggable. Then when it hit another movieclip on stage, is there any way to show up the instance name hit by the circle_mc?
for (var i:int = 0; i < _totalRecObjects; ++i) {
circle_mc.hitTestObject(this["rec" + i]);
}

CKEditor dialogs: referencing input fields by ID

Each input field in the CKEditor dialogs are renamed with a unique number, but the number changes depending on what options are visible.
I need to reference 'txtUrl' which has an id something like #35_textInput.
So far I have discovered that something like this should work:
alert(CKEDITOR.instances.myElement.document.$.body.getId('txtUrl'));
But it doesn't. Please help.
#Rio, your solution was really close! This was the final solution:
var dialog = CKEDITOR.dialog.getCurrent();
dialog.setValueof('info','txtUrl',"http://google.com");
return false;
var dialog = this.getDialog();
var elem = dialog.getContentElement('info','txtUrl');
within an onchange part of an element I now use
dialog = this.getDialog();
alert(dialog.getContentElement('info', 'grootte').getInputElement().$.id);
and it gives 'cke_117_select' as a result. (It's a selectbox)
alert(dialog.getContentElement('info', 'txtUrl').getInputElement().$.id);
gives 'cke_107_textInput'.
I think this is what you (or other visitors to this page) are looking for.
SetValueOf still doesn't provide the id, which you may need if you want to do more than fill a text field with a certain text.

Resources