Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Browse/edit form as subform Topic is solved

Questions related to using nuBuilder Forte.
Post Reply
elbrownos
Posts: 5
Joined: Fri Oct 04, 2024 2:14 pm
Has thanked: 3 times

Browse/edit form as subform

Unread post by elbrownos »

Hi All

I'm new to nuBuilder (and web development in general) so hopefully this is an easy question.
I'd like to create a browse-edit form that acts as a subform of another browse/edit form.
Say there are Projects, and each project has items of equipment, and each item of equipment has components.
So I have a browse/form called Projects. In the Project edit form I have a button that opens another browse/edit form called Equipment. And in the Equipment edit form I have another button that opens Components.
How do I make it so that the Equipment form only includes items relating to the Project that it is under, and the Component form only includes items relating to the Equipment that it is under?

Thanks in advance.
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: Browse/edit form as subform

Unread post by steven »

Hi elbrownos,

Can you share a copy of you database or provide some screen shots?


Steven
A short post is a good post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Browse/edit form as subform

Unread post by kev1n »

Use Hash Cookies as described here.
elbrownos
Posts: 5
Joined: Fri Oct 04, 2024 2:14 pm
Has thanked: 3 times

Re: Browse/edit form as subform

Unread post by elbrownos »

Hi, thanks for your help. Sorry I couldn't follow how to use hash cookies to do this.
I've attached my database.
The first option uses iframes, the second uses buttons. I would prefer to get the buttons option working.
The behaviour I'm trying to implement is:
If I go into Projects and create two projects (say "Project 1" & "Project 2").
Then from "Project 1" I create an equipment "Project 1 Equipment 1" and from "Project 2" I create "Project 2 Equipment 1"
When I go into a project I only want to be able to see the equipment that belongs to that project.
Likewise for a further level of "Components" that belong to "Equipment"
Hope that makes sense.
You do not have the required permissions to view the files attached to this post.
elbrownos
Posts: 5
Joined: Fri Oct 04, 2024 2:14 pm
Has thanked: 3 times

Re: Browse/edit form as subform

Unread post by elbrownos »

Perhaps a simpler question -
A subform table has a foreign key field for the master record ID.
What is the mechanism for the master record ID to be copied to the subform foreign key ID, and what is the mechanism for the subform to only display records where the foreign key ID matches the master record ID?
This is the behavior I want to duplicate with browse/edit forms.
nc07
Posts: 118
Joined: Tue Jun 04, 2019 4:05 am
Has thanked: 5 times
Been thanked: 22 times

Re: Browse/edit form as subform

Unread post by nc07 »

elbrownos wrote: Tue Dec 03, 2024 10:02 pm Perhaps a simpler question -
A subform table has a foreign key field for the master record ID.
What is the mechanism for the master record ID to be copied to the subform foreign key ID, and what is the mechanism for the subform to only display records where the foreign key ID matches the master record ID?
This is the behavior I want to duplicate with browse/edit forms.
Hy, you could do some thing like this; in the Js of browse/ edit form of child form, use the below code, replace the brdngn_id with the id of your foreign key ie. field that will hold your parent id.

Code: Select all

var parentid = parent.nuCurrentProperties().record_id;
 if ($('#brdngn_id').val() ===''){
        $('#brdngn_id').val(parentid).change();
        
    }
hope this helps.

Regards
Nilesh
elbrownos
Posts: 5
Joined: Fri Oct 04, 2024 2:14 pm
Has thanked: 3 times

Re: Browse/edit form as subform

Unread post by elbrownos »

Thanks Nilesh! it works if my child form is an iFrame.
How would I do the same thing if my child form is opened via a button?
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: Browse/edit form as subform

Unread post by steven »

Hi elbrownos,

Change the SQL to include Hash Cookies - as kev1n mentioned.

Code: Select all

SELECT * FROM Equipment
WHERE eqp_equipment_short_code like '#prj_project_short_code#%'

equip.png

And you'll get this...

after.png


Steven
You do not have the required permissions to view the files attached to this post.
A short post is a good post.
nc07
Posts: 118
Joined: Tue Jun 04, 2019 4:05 am
Has thanked: 5 times
Been thanked: 22 times

Re: Browse/edit form as subform

Unread post by nc07 »

elbrownos wrote: Wed Dec 04, 2024 10:36 am Thanks Nilesh! it works if my child form is an iFrame.
How would I do the same thing if my child form is opened via a button?
you can can create a function and call it on onclick event of the button;

Code: Select all


  function addnewreadings() {
    var rid = nuCurrentProperties().record_id;
    if (rid === '' || rid === '-1') {
        alert('Please save the fumigation details first before updating the Concentration reading');
        return;
        //nuSaveAction();

    } else {
        sessionStorage.setItem("fum_id", rid);
        nuPopup('64f6912de704de1', '-1', '', '');

    }
}

function newreading() {
    nuPopup('64f6912de704de1', '-1', '', '');

}
and in the popup form you can retrieve the Parent key like this:

Code: Select all

if (nuFormType() === 'edit') {
    // Set address if opened from an address
    var refA = sessionStorage.getItem("fum_id");
    console.log(refA);

    if (refA !== null && refA !== '-1') {
        $('#fumigations_id').val(refA).change();
    } else {
        nuClosePopup(parent.nuGetBreadcrumb());
    }
}

Hope this works for you, make necessary changes according to your needs.
elbrownos
Posts: 5
Joined: Fri Oct 04, 2024 2:14 pm
Has thanked: 3 times

Re: Browse/edit form as subform

Unread post by elbrownos »

Thanks for your help everyone, I've got it working how I wanted.
Post Reply