Jump to content

Selecting portal row to add related record


deego55

This topic is 6517 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi. I have a main table, contracts table and amendments table. Main can have multiple contracts and contracts can have multiple amendments.

I have a portal for contracts on the main table. I can successfully add multiple contracts. Now I need to be able to select a contract row and be able to add an amendment (or several) for that contract record. How would this be handled?

Thanks for any help!

Link to comment
Share on other sites

I used the following script for the button. seems to work well

Set variable [$parentID ; value: Parent::ParentID]

Freeze Window

Go To Layout [ChildLayout]

New Record Request

Set Field [Child::ParentID ; $ParentID]

Go To Portal Row [Last]

Commit Records/Requests

I have several instances in my solution where i need to add related records and this seems to work well in every case. This is the first time i have tried to use in within a portal, however.

Link to comment
Share on other sites

QUESTION:

Can this technique be used in a 1-to-1 situation? I want the ability to have a button trigger a script like the above, but only allow one related record. For instance, if i have a project and want to add contract information. A project can only have one contract.

Link to comment
Share on other sites

wrap the whole thing in :P

If [not isempty(Contract::ContractID)]

The rest of your script here

Else

Show custom dialog "Project already has a contract"

End If

I dont get what the "go to Portal Row [Last]" Step is doing in there though... in fact, your script does not seem to accomplish what you had originally asked for: create a new record related to a related record (grandchild). It looks like this would just create a child (Contract) record, and not a grandchild(Amendment) record, if you ran it from the MainTable.

-Raz

Link to comment
Share on other sites

Thanks Raz! although shouldn't it be if[isempty]?

I was running the script from within the Contract Portal to create the amendment. I added the button to the portal row. The go to Portal Row step was so that the cursor would move to the newly created blank Portal row.

Although now i just realized i cannot have multiple contracts, so i do not need a contract portal.

Edited by Guest
Link to comment
Share on other sites

although shouldn't it be if[isempty]?

Indeed!

But dont you mean something more like:

"I was running the script from within the AMENDMENT Portal on the Contracts table layout to create the amendment."

Or else I still dont get it...

Edited by Guest
Link to comment
Share on other sites

I was running it from within the contracts portal on the Main table layout. it was working...?

im a novice so maybe i was doing something i havent mentioned.

another question while i have your attention :P

Is it possible to place related fields directly on a layout and use a similar button script to add a new related record and display the blank fields for that record? and then to add navigation buttons to cycle through the related records on the main layout?

sorry if didnt explain that well!

Link to comment
Share on other sites

it was working...?

I would doublecheck just to make sure - I don't see how from your description, but I suppose, if it works...

As to your second question:

Yes.

I am getting the feeling that you haven't discovered the "allow creation of related records" feature yet.

If you check this box in the relationship dialog in Define Fields, you can automatically create related records through any portal or related field based on that relationship. Just click in the field and once you add any data a record will be instantly created in the related table without any scripts or calculations.

It is much easier to cycle through related Parent records than child records through just related fields (directly on layout, not in portal). Do remember that Parent and Child are descriptions of how keys are handled across relationships, not of the tables themselves. It is quite possible for a record to be both a parent and a child of another record.

Before we try and do that though, why not just use a portal that displays only one row with a scrollbar that allows you to cycle through the records? Much simpler to do.

Edited by Guest
Link to comment
Share on other sites

I know of the "allow creation of related records" feature. But i dont want to allow users to just enter the field and add a new record. I need to have a button that will add the related record. So when they first create a parent record, they cannot enter anything into the related fields until they press the "add related record" button

Ok, im an idiot. I didnt think of creating a one row portal that would encompass all of the fields in their current layout. i need the fields to be in a particular layout, that encompasses a large portion of the screen. i have been thinking that portals are only for having a single row of fields.

i can just create a large portal and place all the fields inside and use the same script as above...i think. right?

sorry im so naive! thanks for the input.

Link to comment
Share on other sites

Don't sweat it, one of the costs of FM being able to do so many things so easily is that you tend to feel kind of silly when you suddenly see the simple solution to the problem that has been dogging you for hours. I am glad you have a good reason for not using the "allow creation" feature.

i can just create a large portal and place all the fields inside and use the same script as above...i think. right?

Yes (although I still have my reservations about the script), but it strikes me a bit odd that the portal would have to be so large. If you really are using the majority of your layout to access related fields over a single relationship, why not switch the layouts table to that of the related one? Then, you would just display a few related Main Table fields, and see the actual 'child' record itself. Now you can 'scroll through the child records' with simple Go to next record buttons.

Link to comment
Share on other sites

the problem with switching the layout table is that i have a tabbed interface on the layout and every tab contains fields from a seperate related table, mostly in portals.

im still deciding what the best method would be. i am not too fond of the idea of having such a large portal either.

Link to comment
Share on other sites

the problem with switching the layout table is that i have a tabbed interface on the layout and every tab contains fields from a seperate related table, mostly in portals.

Why is that a problem? FM7+ can show related fields many levels deep. You should be able to just switch the layout table and still have the same related fields and portals display (assuming your relationships are correct).

In other words, if you had a User table related to Projects UserID=USER ID, You can display User::UserName on a layout based on Contracts or Amendments that will show the same data through secondary relationship as if it were on Projects, the table it was directly related to.

Link to comment
Share on other sites

This topic is 6517 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.