Page 1 of 1

In memory FoundSet

PostPosted: Thu Aug 11, 2016 11:54 am
by jeffrey.vandenhondel
Hi again :),

I get the following error message.

Code: Select all
Exception executing calculation: show_filter_result of table temp_9_66a7fe01_5cad_4707_9cf0_220c2a519bf2, error: org.mozilla.javascript.EcmaError: ReferenceError: "elements" is not defined.
ReferenceError: "elements" is not defined.
   at show_filter_result (show_filter_result_)


This is my code:
Code: Select all
   var countLabel = form.newLabel('countLabel', 420, 10, 240, 28);
   countLabel.name = 'count'
   countLabel.styleClass = 'result_title';
   countLabel.dataProviderID = 'show_filter_result';
   var count = "function show_filter_result() {\
      var filterSize = foundset.getSize();\
      if (filterSize == 1) {\
         elements.lblResult.text = i18n.getI18NMessage('afl.lbl.oneInvoiceFound');\
      } else {\
         elements.lblResult.text = i18n.getI18NMessage('afl.lbl.thereAre') + ' ' + filterSize + ' ' + i18n.getI18NMessage('afl.lbl.invoicesFound');\
         }\
      };";
      
   var   dataSource = solutionModel.getDataSourceNode(form.dataSource);
      dataSource.newCalculation(count, JSVariable.TEXT);
      form.getLabel('countLabel');


I tried to create a in memory calculation.

Re: In memory FoundSet

PostPosted: Thu Aug 11, 2016 4:25 pm
by Bernd.N
Hi Jeffrey,
I would try to make the code more simple. So in case it is not necessary to stuff the function into a var string, I would turn that into a normal JS function first.

BTW, foundset.getSize() will show you max. 200 records, even when 1.000 invoices exist.

Re: In memory FoundSet

PostPosted: Thu Aug 11, 2016 6:34 pm
by patrick
Without trying to understand what you are trying to accomplish I do see two things that go completely wrong:

1. A calculation resides on the data level and can never deal with forms or elements of such

While a form can use calculations when it is based on a table, a calculation is lower in the stack than a form and therefore does not have access to forms.

2. A calculation calculates a value and therefore always needs to return something

Your code is a method, not a calculation. It tries to manipulate, not calculate something.

Re: In memory FoundSet

PostPosted: Thu Aug 11, 2016 9:07 pm
by Bernd.N
I would recommend to use the solution model only when it is really necessary.
If it is, I would first study existing code to get some ideas of strategies to use it.
Your learning curve will be much steeper.

The Data Record Editor is an example for the use of the solution model, it shows any record in a window in editable mode.
So it just builds a large detail form with all necessary fields when you give it a table structure.
https://www.servoyforge.net/attachments/download/1571/Screenshot_Example.PNG

You can get the sourcecode here:
https://www.servoyforge.net/projects/editwindow

Re: In memory FoundSet

PostPosted: Sat Aug 13, 2016 2:49 am
by Bernd.N
Ok, now I finally got what you wanted to do and mixed up, after reading Patrick's comment twice.
You could try the concept of a calculation (= automatically calculated (virtual or physical) field of a table) first on a table with manual coding, to get what it's doing.
Click the tab "Calculations" in the table editor inside Servoy developer and add a new calculation there.