controller.loadRecords or foundset.loadRecords

Questions and answers for designing and implementing forms in Servoy

controller.loadRecords or foundset.loadRecords

Postby d.pearce » Wed Jan 02, 2013 8:51 pm

Quick question,

is there ever a reason to use the controller.loadRecords() as opposed to the foundset.loadRecords().

The reason I ask, is that i think there is a servoy glitch or even bug with the controller. function.

This is I think related to calling it from a sub function on another form.

i.e
Code: Select all
function a {

function b()

}

function b{

form2.controller.loadRecords(foundset.id);

... then do some stuff to print a pdf on form2.
}


We have found that sometimes the wrong record has been attached to an email we are sending when compiling a few attachments.
Recently it occurred after i had a script, which i decided to split out into 3 subscripts for ease of reading it, and this it appears started to cause a similar problem to that which I have seen before.

Anectdotally, it doesnt appear to be an issue when making the call from the first function on the form on which it is called, only when you go to a sub function on the same form. I have also checked the foundset.id and this is correct in the sub function, as another document, which uses it works fine within the same script.

I am hoping that using the form2.foundset.loadRecords(foundset.id), will work, and it appears to.

So is the controller.loadRecords function essentially not necessary as the founder. function will do the same thing, even if i use the controller.print in the next line?

A strange one!

David
d.pearce
 
Posts: 11
Joined: Wed Jul 18, 2012 11:48 am

Re: controller.loadRecords or foundset.loadRecords

Postby Harjo » Wed Jan 02, 2013 10:54 pm

Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: controller.loadRecords or foundset.loadRecords

Postby d.pearce » Wed Jan 02, 2013 11:45 pm

Yes its interesting

will need a clear head in the morning to think about what its saying. Maybe a coffee and a tea!

Interesting all I am doing is loading in the id of the record I am on into a form with a template for printing a report, so i am not sure that either shouldnt work.

It was the changing of the function which loaded the record into the other form before issuing the print command to create a pdf, that has worked fine for ages, but it was only when i moved it to a sub function on the same primary form that it seemed to do this sporadically.

At first i thought it was loosing the foundset.id when moving to the second function, even though it was on the same form js as the first, but this cant be the case as one letter, which sends a global text variable to a form with a letter template and everything as a global displays this id as it put in the variable as our ref: '+foundset.id and that is displaying fine!

I will try to reproduce it somehow, but I have changed to controller.loadRecords() and I will see if in ViVo this stops the problem.

David
d.pearce
 
Posts: 11
Joined: Wed Jul 18, 2012 11:48 am

Re: controller.loadRecords or foundset.loadRecords

Postby d.pearce » Tue Jan 22, 2013 7:48 pm

OK, I have managed to get the error with some debugging information:

Code: Select all
function DIPATCH_REHAB_PI() {
   forms.invoice_ppi.foundset.loadRecords(foundset.invoice_rehab_physio1pi_id)

   if (forms.invoice_ppi.foundset.id != foundset.invoice_rehab_physio1pi_id) {
      var _body = 'foundset.invoice_rehab_physio1pi_id:' + foundset.invoice_rehab_physio1pi_id + '\n\
forms.invoice_ppi.foundset.id: ' + forms.invoice_ppi.foundset.id + '\n\
id: ' + foundset.id
      globals.send_mail('xxxxx@me.com', 'error@episource.co.uk', 'Physio Invoice Error', _body)
   }

   var success = plugins.pdf_output.startMetaPrintJob()
   if (success) {
      forms.invoice_ppi.controller.print(true, false, plugins.pdf_output.getPDFPrinter());

   }
   var thepdf = plugins.pdf_output.endMetaPrintJob()

   var attachment4 = plugins.mail.createBinaryAttachment('physioinvoice_' + foundset.id + '_' + forms.invoice_ppi.foundset.id + '_' + foundset.invoice_rehab_physio1pi_id + '.pdf', thepdf);

   return attachment4;
}


OK< so i didnt get an email with any error, but the file sent to the physiotherapist had the name:

physioinvoice_59826_100682_293338.pdf3756280257947053965

SO this must prove that the record is loaded correctly into the found set and was clearly equal to the stored id, and then in two lines was changed!!!

This is happening a couple of times each day, but is not in every case.

Help is this a bug, shoudl i go back to using the controller.loadRecords instead!
d.pearce
 
Posts: 11
Joined: Wed Jul 18, 2012 11:48 am

Re: controller.loadRecords or foundset.loadRecords

Postby Harjo » Tue Jan 22, 2013 8:45 pm

This look strange indeed.
the only possible way is that: controller.print(), does strange stuff with the foundset, don't know, but maybe you can workaround it...

why not holding the id (or a whole record object) right at the beginning in a var, and than use that in the end in the mail??

and ofcourse after that, do some more debugging, so you can reproduce this, and Servoy could take a look at this..
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: controller.loadRecords or foundset.loadRecords

Postby d.pearce » Wed Jan 23, 2013 2:10 pm

OK, even stranger. I have found this morning that my error email did trigger. ( i just messed up the from address so didn't see it.)

SO the result was:

foundset.invoice_rehab_physio1pi_id:293430
forms.invoice_ppi.foundset.id: 100682
id: 63468

This means that the command:

Code: Select all
forms.invoice_ppi.foundset.loadRecords(foundset.invoice_rehab_physio1pi_id)

   if (forms.invoice_ppi.foundset.id != foundset.invoice_rehab_physio1pi_id) {
      var _body = 'foundset.invoice_rehab_physio1pi_id:' + foundset.invoice_rehab_physio1pi_id + '\n\
forms.invoice_ppi.foundset.id: ' + forms.invoice_ppi.foundset.id + '\n\
id: ' + foundset.id
      globals.send_mail('xxxxx@me.com', 'error@episource.co.uk', 'Physio Invoice Error', _body)
   }


Loaded the wrong record into my found set!!!! It is intermittent, but happening once or twice every day. The record is created a few minutes earlier and saved, hence the id is on the main table as an fk.

Most odd. I have put the script on the form now and used 4 methods to get the record, (foundset.load, controller.load, then foundset.find()) so maybe i can see if one works even after the foundset.loadRecords failure.

David
d.pearce
 
Posts: 11
Joined: Wed Jul 18, 2012 11:48 am


Return to Forms

Who is online

Users browsing this forum: No registered users and 5 guests