Have main form that has navigator buttons on top to go between a couple of related forms. What I want to do is set it so that when the user searches and finds an individual on the main form and clicks on one of the other buttons it will bring up a form with that individual other information.
Right now when the user clicks on the button that takes them to another form they have to enter the individual’s id again.
Can this be done using buttons?
Or do I have to try and set up tab panels again. (See below).
Originally when we evaluated teh software I did setup tab panels to go between forms but either the jdbc driver did not work properly or the version of Informix we use on the backend was not working properlye so that the search would not work. With the new verison of Servoy and the fact that Informix was recently updated, I found some of the problems have disappeared after the upgrade.
Would like to use what we have instead of trying to recreate using tabpanels.
Is this possible? I have posteded this before on the Forms list but no one has answered.
Please help.
If I understand you right, you want to move to another form and when you are there, look at the same record that you had in the form you came from?
If yes, there are many ways to do this:
if both forms are based on the same table and you have not checked “use seperate foundset” on any of the two, Servoy keeps these forms in synch. That means, if you search in form A and find one record, form B shows the same record. So there sould be nothing to do…
you could create a self-relation between the table from primary key to primary key. Then in your button method you do
forms.B.controller.loadRecords(self_relation)
before you show form B. This will load the one record you have found in form A in form B.
you could let your button method search the same record in form B by doing something like
forms.B.showMyRecord(recordId)
and in form B you have the method “showMyRecord” that does
var vRecordId = arguments[0] // will receive the recordId that your button method passed
controller.find();
recordId = vRedordId // search for the ID that was passed
controller.search()
But maybe you have to explain your problem a bit better…
That is correct. I don’t know if this will explain it further but here goes of what I want. Please let me know if your reply above would work.
Both forms are not based on the same table each has their own table.
Related by a PK of assigned serial number from a backend database.
I would like it so if they click on the button that lists the second form when the that form loads it would bring up the person I think that is what you are explaining in #2? #3?
For example. If I am on a particular form(Form A) and data is showing for the first person that loads or if I look a someone up on that Form A lets call them Joe Smith and their data is showing. I want to be able to switch (Press the button) to Form B, Form C etc. I want to see Joe Smith’s information that pertains to Form B(coming from a different table) or Form C etc.
Form B or Form C has different information coming from differnet table that Form A did in the backend database but is related by a PK and exampe would be id number.
Another question, would this affect adding a new record to form B or C?
I really appreciate the help!!
but the first one is a little bit shorter
So you have to define relationships between your tables (I called them relationA_to_relationB) in this example.
Haven’t tried this yet but I am planning on doing this today and I should just try it but I do have a couple more questions, HJK or Patrick.
I am probably making this more complicated than I need to.
Question #1
All the forms have the same PK, do I have to have a “main” form that will just go between the other forms, or can can I set up more than one statement for controller between the forms so the same individual will appear if I switch from one of the other forms back to say the first form? Ex. I am now on Form C, search, pull someone up, switch to form A same individual will come up, even though I just set it up as in your example between A and B?
Question # 2
This is just understood but I can still enter data, change data, or add a new record in these forms too correct? They will not be for viewing only? What happens in Form B if there is no record for that individual that was searched for in Form A?
Error? Blank form?
Sorry for the stupid question, but am new to Servoy.
Thanks again!
I think this has not many to do with Servoy, but your database-design. (normalization) You don’t have to create a new table for a forum, just to show it in a tabpanel. (you can use a self-join for that)
So I think you have to tell us more about your db-design, before we can give you the right direction.
Buttons instead of the tabpanels control between the forms. (see inital message)
One form to One table.
Each of these tables have a field in them that is the PK and the PK is a number that is the same in all tables to be able to link them together.
Some of the tables have multiple records for the same PK, some are existing tables that are shared with a seperate application and still others are unique and used only by this one client.
I have relationships set between the tables using the PK under relationships in Servoy.
If the client does a look up in one form then they want to be able switch to the other form(seperate table same PK with relationship to table/form they just searched on) and see that individual on the form he switched (clicked button) to.
I can’t explain it any clearer than this.
Thank you for the suggestions but it is still not working.
I am reposting so someone can tell me what I am doing wrong.
On Form A I created a button called TEST to test the suggestions I received.
1 Each form does not have “use seperate found set” checked.
The two forms are not based on the same table but two seperate tables.
Table A and Table B. The PKs or row idents are equal and under relationships, global,
relationship set up between A and B under table A and in Table B from B to A.
Tried 2. Placed this in a method and called it up in the ON Action statement on the TEST button’s properties.
I get this error when I press the button: “Conversion Error: The undefined value has no properties
calling loadRecords.”
My relation is based on the PKs from table A to table B (Form A to Form B) which are the same.
I then tried this next suggestion 3 with no luck.
I get this error when I press the button: "TypeError: Object Arguments is not a function. (showmyrecord; line2)
FormB.showmyrecord "
I think I have been working on this too long and am getting really confused on where these statements/methods for # 2 and #3 need to be placed.I summed up below what my objective is.
I really don’t think I am putting the methods in the correct place.
Tell us the name of the database server that you set in preferences and I can either create a dummy DB or through the import we can nominate one of our existing ones to load into.
I got it!!!
I am still testing this but I think this will work.
On my main form A I created a test button to switch to Form B.
I then created the button Method in the Editor using the second or long suggestion from HJK. Thanks HJK!
I then went to the OnAction property for the test button and placed the method name to trigger the switch.
When the test button is pressed from Form A it will switch to the Form B and now brings up all records related to the first form.
Now this is where it gets strange.
What I found that was different from what I was doing before was that inside the Editor when I created the button method; I had to click on the name of the form, go down to relationship, and click the relation I wanted to use to get it to work. When I was having so much trouble before I tried typing the name of the relation within the parenthesis instead and when I tried the button it would not work and gave those errors.
So it seems it comes down to how I was working in the method portion of the Editor.
Thanks to all who responded, you probably thought it was silly that the suggestions wouldn’t work.
Now I just need to figure out the correct coding in Servoy to show only the records in Form B by the value of one of the fields coded in table. Something like a select statement like
select tableB records where tableB.field in (“CodeA”, “CodeB”).
Anyone have any suggestions on this, please feel free to reply?
nramaley:
Now I just need to figure out the correct coding in Servoy to show only the records in Form B by the value of one of the fields coded in table. Something like a select statement like
select tableB records where tableB.field in (“CodeA”, “CodeB”).
Anyone have any suggestions on this, please feel free to reply?
You mean…
var sQuery = "SELECT tableB.pkField FROM tableB WHERE tableB.specificField in ('CodeA','CodeB) ORDER BY pkField;";
forms.FormB.controller.loadRecords(sQuery);
Yes, this is exactly what I was looking for!
I added to my button method and limited the data to just those two codes.
This is working great for one table.
Thanks you!
Now, here is one more question to take this a step further.
What would be the coding if I incorporate your above example to limit the data from table B when there is a relationship between two tables, Table A and Table B?
I tried this in my button method and it did not limit the data being shown to just those two codes only byt the relationship between A and B.
var sQuery = "SELECT tableB.pkField FROM tableB WHERE tableB.specificField in ('CodeA','CodeB')ORDER BY tableB.pkField";
forms.aa_rec.controller.loadRecords(sQuery);
forms.aa_rec.controller.loadRecords(relationA_to_relationB);
forms.aa_rec.controller.show();
I would like to know how to incorporate the relationship so that the data that shows is limited by the codes in B and the relationship from A to B.
Again, many thanks!
nramaley:
I would like to know how to incorporate the relationship so that the data that shows is limited by the codes in B and the relationship from A to B.
So if I understand you correctly you only want to see the records in A that have related records in B and filtered on those 2 codes in B.
You can do this with a join.
SELECT tableA.pkField FROM tableA,tableB WHERE tableA.pkField=tableB.fkField AND tableB.specificField in ('CodeA','CodeB') ORDER BY tableA.pkField;
forms.aa_rec.controller.loadRecords(sQuery);
tableA.pkField=tableB.fkField is the join between the 2 tables. If you use more joins between those 2 tables just add them with the AND between the joins.
Forgive me for not responding to your post sooner.
So if I understand you correctly you only want to see the records in A that have related records in B and filtered on those 2 codes in B.
You can do this with a join.
Actually what I want is to see on Form B the records from table B that are related to table A as defined in the relationship relationshipA_to_relationshipB. With the addition of limiting the data being shown on Form B by CodeA and CodeB.
The other little twist is Table B has two PKs or row-idents and Table A has one PK. They share just one PK between them.
In the select statement below, I had to add Pk2 in front of Pk1 from TableB because alphabetically Pk2’s name is comes ahead of the PK1. TableB’s Pk1 = PK1 from TableA.
I tried this using your coding:
var sQuery = "SELECT TableB.Pk2, TableB.Pk1 FROM TableB, TableA WHERE TableA.Pk1 = TableB.Pk1 AND TableB.Field in ('CodeA','CodeB')ORDER BY TableA.Pk1, TableB.Pk1";
forms.FormB.controller.loadRecords(sQuery);
forms.FormB.controller.show();
It did limit the data that was shown from TableB on FormB two those two codes. The problem now is that if I do a find/search on Form A(TableA) by its Pk1 and then click on the button that will use the above method to bring FormB up it does not show the data for that record I just selected in FormA.
However, if I switch back to just the relationship method not limiting by the codes :
I am able to do a find and search (using Select at the default toolbar), then click on the button that triggers the relationship method and it brings up just that Pk1’s data on FormB.
So how do I mimic this using the Select statement so that it limits the data by the two codes
You should be able to modify the code which Robert supplied to add in the table A pk value as a criteria as follows:
var v_table_a_pk = forms.TableA.Pk1
var sQuery = "SELECT TableB.Pk2, TableB.Pk1 FROM TableB, TableA WHERE TableA.Pk1 =' + v_table_a_pk + ' AND TableA.Pk1 = TableB.Pk1 AND TableB.Field in ('CodeA','CodeB')ORDER BY TableA.Pk1, TableB.Pk1";
forms.FormB.controller.loadRecords(sQuery);
forms.FormB.controller.show();
So you are setting a variable to the current record being viewed in TableA and then passing this into the query string
Error loading primary key data…
Character to numeric conversion error…
This is what I did
var v_table_a_pk = forms.TableA.id;
var sQuery = "SELECT TableB.pk2, TableB.pk1 FROM TableB, TableA WHERE TableA.id = TableB.id AND TableA.id = ' + v_table_a_pk + ' AND TableB.Field in ('Code1','Code2')ORDER BY TableA.id, TableB.id";
forms.TableB.controller.loadRecords(sQuery);
forms.TableB.controller.show();
In debug the variable looks like it is set to a number so it seems it is loading the pk1 on the var statement correctly.
What might be causing this?
Thanks again for the help