OnShow problem from one form to another

Hi,

I am trying to get another form (form2) to load up a record once a user clicks on a field in a portal on form1. I cannot get it to work? I am wondering if it is where I am putting the following code:

Form1 - on focus of a field in a portal:

globals.selectedquote = clients_to_quotes.quotenumber;
globals.varNav1 = 1; - I use this as a flag for Form2 to check
forms.Quotes.controller.show();

the - in the OnShow of form2

if (globals.varNav1 == 1)
{
var queryq = ‘Select * from quotes where quotenumber = "’ + globals.selectedquote + ‘"’;
var maxReturedRows = 10;//useful to limit number of rows
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), queryq, null, maxReturedRows);
controller.loadRecords(dataset);
}

BUT - no record loads and several boolean test I run on some check boxes all fail???

Am I putting the code on Form2 in the wrong event? I have tried it in OnLoad as well but no change. I have confirmed that the query returns a result in an external MySQL tool.

Dave.

what error are you getting?
Did you try only quering the primary key?
var queryq = ‘Select “myPK” from quotes where quotenumber = "’ + globals.selectedquote + ‘"’;

I am getting an empty record set?

The quotenumber is not the primary key but it is indexed. I have run it in Navicat and it returns one row. I used the debugger and the syntax of the query appears fine.

Just return empty and then I have some if statements which check for values 0/1’s to check or uncheck boxes - these of course then fail as they are null???

I have worked around this for now using this code in the onFocus on Form1

forms.Quotes.controller.showRecords(clients_to_quotes);

Certainly easier - but I would have thought the other way should have worked. Am I trying to make this too hard???

Dave

Hi Dave,

Me again !! :-)

I think this is a lot simpler than you think

Try:

forms.Quotes.controller.showRecords()

attach this method to the onAction event of the portal field as you don’t need to have an onFocus event (make sure that the portal field is set to NOT be editable)

Does this not work or do you need something else as a result ?

Harry

forms.Quotes.controller.showRecords(clients_to_quotes);

this is much easier indeed.

regarding your other code:

controller.loadRecords(dataset); 

the dataset should only contain the primary key but you are quering all columns:

var queryq = ‘Select * from quotes where quotenumber = "’…

Hi Dave,

Weighed while there was an answer from you AND messed up by not including the relation in the showRecords() function !!
What a wally I am :-|

Harry Catharell:
Hi Dave,

Me again !! :-)

I think this is a lot simpler than you think

Try:

forms.Quotes.controller.showRecords()

attach this method to the onAction event of the portal field as you don’t need to have an onFocus event (make sure that the portal field is set to NOT be editable)

Does this not work or do you need something else as a result ?

Harry

:oops:

Cheers
Harry

Harry,

Thanks. The key bit of info I was missing there was that dataset is the PK ONLY. I actually assumed it was a results set and the show() command was passing that entire results set to the form.

Turns out I got around it by using this on the OnFocusGained for the key field in the portal:

forms.Quotes.controller.showRecords(clients_to_quotes);

I think because of my background in REALbasic and FoxPro, I am trying to over-complicate these issues by thinking SQL and query based methods all the time. I keep forgetting Servoy lets me create these relations with little effort.

I also had a similar issue when a Quote screen converts a quote to an invoice. The data needs to be inserted into an Accounts table. After messing around with SQL, all I have done is created a new relation named quotes_to_accounts and placed a portal on the form but have moved it off the ‘canvas’ so that the user can’t see it. The insert is really easy then.

Hope this makes sense…

Thanks

Dave.

Hi Dave,

Makes good sense.

Couple of points :

  1. Why do you need an onFocusGained event ? If this event is only providing the trigger for the method to go to the related record set then I would think that you would be better making the field non editable and using an onAction event for the field (or perhaps the whole portal row ?)
  2. In Servoy, portals are good but tabpanels are better by far so it really is worth checking out the tabpanel tutorial on the Servoy Magazine web site - if you haven’t done so already !
  3. I am envious of you being able to think so fundamentally in SQL so don’t knock this ! I essentially come from a FileMaker background and have had to drag myself, kicking and screaming, into the world of SQL and javaScript !! Servoy gives you wonderful RAD capabilities which knock the relative socks off FileMaker but the real power lies in what you can do behind the scenes by running your SQL queries. But you are correct about Servoy versus SQL where the reality is ‘don’t use a sledgehammer to crack nuts !’

Anyway, how’s the weather looking in Adelaide for Christmas !?

Been down to Sydney and Brisbane but never managed to get across to Melbourne and Adelaide :-(

Cheers
Harry