Help with setting a form.element via code

I’m trying to use a popup form to, ultimately, set a value on the calling form. I am calling the popup modally but I found in webclient that code execution doesn’t stop when the showformindialog() is called (I was originally going to set a global in the popup and then set my field once the popup was dismissed).

So, another method was required. Since I want the popup to be called from several forms I was hoping to do the following…

  1. on the calling form set a global variable to the field name of what I ultimately want populated
  2. call the popup
  3. user selects value and accepts
  4. popup determines calling form (from getMethodTriggerFormName) and field (from global) and tries to set that to the selected value
  5. popup closes

When I try this I get an error…

Can’t put in a locked scope, name: finance_id, value: 26502

java.lang.RuntimeException: Can’t put in a locked scope, name: finance_id, value: 26502

Here’s the code I’m trying on my popup…

  • finance_id is the field on the popup containing the code I need.
  • formname is the correct value
  • elementname is the correct value as globals.main_finance_id_field is set on my calling form
  var formName = application.getMethodTriggerFormName();
  var elementName = globals.main_finance_id_field;
  application.output('formname is '+ formName);
  application.output('elementname is '+ elementName);
  forms[formName].elements[elementName] = finance_id;
 	application.closeFormDialog();

I’m sure my noob approach can be substituted with something alot more clever - any ideas ?

Thanks in advance
Mark

Hi Mark,

I am calling the popup modally but I found in webclient that code execution doesn’t stop when the showformindialog() is called (I was originally going to set a global in the popup and then set my field once the popup was dismissed).

That’s right a modal dialog cannot block a thread’s execution on the server.
The easiest way to do this in Web Client is to use an onHide() handler for the dialog form.
You can attach it back to a method in the calling form to continue the process.
Or if you need it to be more flexible, (used by many forms) you can pass in and store a function object to call as a call-back.
If you want to do that, below is a hypothetical code scenario

Hope this helps,
Sean

dialog form methods:

shows the dialog w/ an optional callback:

function showMe(){
    var initialStuff = arguments[0];
    callbackFunctionName = arguments[1];
    application.showFormInDialog(this);
}

on hide handler to invoke callback:

function onHide(){
    if(callBackFunctionName){
        eval(callBackFunctionName + '('  +otherStuff+ ')')
}

Calling Form methods:

shows the dialog form:

function showDialog(){
    forms.dialogForm.showMe(initialStuff, 'dialogCallBack');
}

handles the callback:

function dialogCallBack(){
    var modifiedStuff = arguments[0];
    // go to town
}

}

Thx Sean - I’ll have to give it a try !

Cheers
Mark

I tried what you suggested and it is pretty cool - all the mechanics work exactly as they should (w00t!!)

BUT… I have a problem… the return value is fine when I dump it out via application.output but the value that displays in the field that is updated on my calling form is not “formatted” correctly…

For example, according to my application.output the value that ‘comes back’ is “26501” (this is an id/foreign key value which is exactly what it should be) but the value that gets populated in the field of interest is “26501.0” - where is this extra .0 coming from ?? The field comes from a column in a table that is a varchar2(20).
There is no defined format on the field on the calling form.

Puzzled…

Hi Mark

This is a Javascript issue that also presents if you import numbers into Servoy. You can strip the extra .0 with with this:

Utils.numberFormat(‘return value’,’yourFormatHere’)

I found that if you strip the return value .0 using the above and then insert it into the field it works, incidentally ‘#’ is the format I used.

Cheers
Gordon

Thanks Gord, that did the trick :D