A simple question that has me puzzled. I am trying to retrieve the dataProviderValue based on the getMethodTriggerElementName function. This is the code.
var elemName = application.getMethodTriggerElementName();
var id = elements.elemName.getDataProviderID()
var resNum = controller.getDataProviderValue(id)
Something is not working properly. The first line works fine, returning the name of the element.
_0arr
Var “id” remains undefined and the method returns the following error on the second line.
The undefined value has no properties calling getDataProviderID.
Callstack:
Calendar.show_Reservation
ConversionError: The undefined value has no properties calling getDataProviderID. (show_Reservation; line 3)
Calendar.show_Reservation
tommygill:
The undefined value has no properties calling getDataProviderID.
This means trying to read a property with the name ‘getDataProviderID’ which does clearly not exist on the element.
In this case it’s the syntax that’s bugging you.
tommygill:
var id = elements.elemName.getDataProviderID()
Servoy now treats elemName as the real name of the element, but it should treat it as a variable.
You can do this by dropping the first ‘.’ and place elemName between brackets.
So the correct syntax would be:
var _elemName = application.getMethodTriggerElementName();
var _id = elements[_elemName].getDataProviderID();
var _resNum = controller.getDataProviderValue(_id);
As you can see I also prefixed the variables with ‘_’ (could be something else as well). This may help you find syntax problems easier, as it is more clear what the variables are.
Another way to get the value is this code:
var _formName = application.getMethodTriggerFormName();
var _elemName = application.getMethodTriggerElementName();
var _id = forms[_formName].elements[_elemName].getDataProviderID();
var _resNum = forms[_formName][_id];
Many Thanks. It seems the devil is always in the syntax.
It works great now and saves a lot of extra coding, which I am not particularly good at. I’m still learning.
Thanks again