Welcome to the nuBuilder Forums!

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

#RECORD_ID# from a subform object

Questions related to using nuBuilder Forte.
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

#RECORD_ID# from a subform object

Unread post by marcvander »

Hey,

I have a form, in which I have a subform. This subform itself has an object. This object is a Select object (dropdown). Here is the SQL query:

Code: Select all

SELECT opportunite_id, opportunite_nom
FROM opportunite
WHERE opportunite_contact_client='#RECORD_ID#'
Though, the dropdown is empty on the subform:
Capture d’écran 2018-05-28 à 14.40.36.png
Is #RECORD_ID# a valid hash cookie on a subform to get the record_id of the main form the subform is on ?
You do not have the required permissions to view the files attached to this post.
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: #RECORD_ID# from a subform object

Unread post by toms »

marcvander wrote: Is #RECORD_ID# a valid hash cookie on a subform to get the record_id of the main form the subform is on ?
No. Try this:

Add this to your main form's js:

Code: Select all

if (nuFormType() == 'edit') {
  nuSetProperty('MAIN_FORM_RECORD_ID', nuCurrentProperties().record_id);
}
(Note: For new forms, record_id is -1)

Then in your SQL query:

Code: Select all

SELECT opportunite_id, opportunite_nom
FROM opportunite
WHERE opportunite_contact_client='#MAIN_FORM_RECORD_ID#'
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: #RECORD_ID# from a subform object

Unread post by marcvander »

Toms, thank you! There is an interesting thing happening:

I added a display object on the main form to display the value of '#MAIN_FORM_RECORD_ID#'. When I enter the form in edit mode, the display object is empty (called "test" in the following screenshot), and thus my subform select object is empty too:
Capture d’écran 2018-05-28 à 17.06.19.png
But then when I click on Arrange objects in the options, that I move the display object containing the value of '#MAIN_FORM_RECORD_ID#', and I save, the display object works and the select object in the subform works as well:
Capture d’écran 2018-05-28 à 17.05.54.png
When I leave the form and come back, again nothing shows in the display and select objects.
You do not have the required permissions to view the files attached to this post.
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: #RECORD_ID# from a subform object

Unread post by toms »

I think #MAIN_FORM_RECORD_ID#' is unknown/not yet set when the subform is created.
Arrangning objects/saving will refresh the form and at that time the hash cookie is available and therefore resolves.

What you could try: Save the record id of the main form to a text input field (e.g.mainformrecordid and use that field as hash cookie in your sql (#mainformrecordid#)

Code: Select all

function nuBeforeSave() {
    if (nuFORM.edited == true) {
        $("#mainformrecordid").val(nuCurrentProperties().record_id).change(); 
   }
    return true;
}
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: #RECORD_ID# from a subform object

Unread post by marcvander »

So I tried, and this time, even after moving an object and saving, nothing shows.

My display object:

Code: Select all

SELECT contact_id
FROM contact
WHERE contact_id='#mainformrecordid#'
My select object:

Code: Select all

SELECT opportunite_id, opportunite_nom
FROM opportunite
WHERE opportunite_contact_client='#mainformrecordid#'
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: #RECORD_ID# from a subform object

Unread post by marcvander »

I think #MAIN_FORM_RECORD_ID#' is unknown/not yet set when the subform is created.
What if we try to define #MAIN_FORM_RECORD_ID# before the subform is created. Like at the moment the user clicks on a line in the browse form, before entering edit form ?
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: #RECORD_ID# from a subform object

Unread post by toms »

marcvander wrote:So I tried, and this time, even after moving an object and saving, nothing shows.
...and there's a field on your form (mainformrecordid) with the record id in it?

marcvander wrote:What if we try to define #MAIN_FORM_RECORD_ID# before the subform is created. Like at the moment the user clicks on a line in the browse form, before entering edit form ?
You could try this:

Code: Select all

function nuSelectBrowse(e) {

    var r   = $('#' + e.target.id).attr('data-nu-primary-key');
    nuSetProperty('#MAIN_FORM_RECORD_ID#', r);
    nuForm(nuGetProperty('form_id'), r, '', '', '1');
    
}
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: #RECORD_ID# from a subform object

Unread post by marcvander »

Hey toms,
...and there's a field on your form (mainformrecordid) with the record id in it?
No there are no record id in it. I try to show the current value of #mainformrecordid# but it is empty.

I tried with your last suggestion, still the same, nothing shows both on the subform select object and on the form display object with this query:

Code: Select all

SELECT contact_id
FROM contact
WHERE contact_id='#MAIN_FORM_RECORD_ID#'
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: #RECORD_ID# from a subform object

Unread post by marcvander »

Solved. A little typo in your last code:

Code: Select all

function nuSelectBrowse(e) {

    var r   = $('#' + e.target.id).attr('data-nu-primary-key');
    nuSetProperty('MAIN_FORM_RECORD_ID', r); //Without #
    nuForm(nuGetProperty('form_id'), r, '', '', '1');
    
}
You put '#MAIN_FORM_RECORD_ID#' instead of 'MAIN_FORM_RECORD_ID'
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: #RECORD_ID# from a subform object

Unread post by marcvander »

In the same idea, I'm trying to implement a function so that when on a 1st form, clicking on a button on this 1st form brings on a 2nd form, and on this 2nd form the record id value of the 1st form is pre-entered in one field of the 2nd form.

To do that, I added this on my 1st form:

Code: Select all

function nuSelectBrowse(e) {

    var r   = $('#' + e.target.id).attr('data-nu-primary-key');
    nuSetProperty('ENTREPRISE_ID', r);
    nuForm(nuGetProperty('form_id'), r, '', '', '1');
    
}
And this on my 2nd form:

Code: Select all

if (nuFormType() == 'edit') {
    $("#contact_entreprise_id").val('#ENTREPRISE_ID#').change(); 
}
But nothing is pre-entered in the field contact_entreprise_id
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
Locked