Best way to get a BO field by name

Hi

By disabling secureJS I've been able to get a field from BO dynamically by using:

var fld = eval("BO.F_Calc");

so I can set/get the value of the field.

But is this the best way to do it? I would rather not have to disable JS security for something this simple... ;-)

To get a handle to the data object of a field:

var fld = BO.F_Calc

fld.setValue(...);

var fld_val = fld.getValue();

fld.setValid(false, "wrong!");

To get a handle to the UI object of a field:

var fld_ui = form.getPage("P_Page1").F_Calc

var fld_ui = page.F_Calc

fld_ui.setVisible(false);

fld_ui.setActive(false);

Once you have your handle to the object you can then call the functions that are part of it. The javaScript API is documented at https://help.hcltechsw.com/domino_volt/1.0/ref_jsapi_objects_and_functions.html

Ok, I may not have been clear enough in my question. I want "F_Calc" to be a variable. This way I can build a JS function that can work on different fields just using a text string to point at the right field.

One use case we have is a function to do some more work by setting some shadow fields based on a value from a lookup. Those fields are named something like F_Calc1, F_No1, F_Cat1 - and the next pair could be: F_Calc2, F_No2, F_Cat2, etc...

So I want to build a function that would have the "index" as argument like: doSomething("1"), doSomething("2"), etc....

I can build that using the "eval" statement as shown - but I just wanted to know if there was a better way, like form.getPage("P_Page1") to get P_Page1...

In that case you would do something like this:

var v = "F_Calc";

var fld = get(BO, v);

if(typeof fld !== "undefined") {

var val = fld.getValue();

}

It is important to check the object exists before trying to call functions on it otherwise the user will get an error.

Great, I'll try that out! Didn't know about the "get()" method.... - and obviously, checking that the object was found is important ;-)