Page 1 of 1

Custom code form - subform

Posted: Wed Nov 24, 2021 2:19 pm
by gerese
Hi Kevin, I need your help.
I have an FF6 form in which information can be added.
I also have an FF0 form that contains as a subform, the FF6 form.
In FF0 I just want to add or delete records in the FF6 subform (the record should not be deleted from the database only the updated FK field in the FF6 subform).
From the properties of the subform I deactivated "delete checkbox".

I added an "Add / Del" button in the FF6 subform, which I want to execute the following:
- if pk <> -1 will run the procedure "deleteCommand" the field FK will be updated with "" (nothing) so that record will no longer appear in the subform FF6, when FF0 form is in edit mode
(works here);
or
- if pk = -1 to open a popup with FF6 and to be able to select a record so as to update FK whit form_id of the form FF0 .... here I am blocked


I added this in custom code of FF0 form, (event from "Add / Dell" button)

Code: Select all

function addDelCmd(event){
    var id = event.target.parentNode.id;
    var pk = $('#' + String(id)).attr('data-nu-primary-key');

    if (pk == '-1') {
    var r1 = nuCurrentProperties().record_id;
    nuSetProperty('ECHI_COMANDA_ID', r1, 0);
                    nuPopup('617efff03300f00', '', '');   //subform FF6

    //    nuClosePopup();
    
    } else {
        nuSetProperty('deleteRow_record_id', pk);
        nuRunPHPHidden("deleteComanda", 1);
            }
}

function afterDeleteRow() {
    nuSearchAction();
}
Procedure for deleting the foreign key (working)

Code: Select all


$pk = "#deleteRow_record_id#";

$qry = "UPDATE echiplucrare SET echi_comanda_id = '' WHERE echiplucrare.echiplucrare_id = '$pk';";
nuRunQuery($qry);

// The function afterDeleteRow() must be declared in the form's Custom Code 
$j = "afterDeleteRow();";
nuJavascriptCallback($j);

Procedure that adds the foreign key (not working)

Code: Select all

$pk1 = "#ECHIPLUCRARE_ID#";
$pk2 = "#ECHI_COMANDA_ID#";
//nuDebug($pk1, $pk2);
nuDebug(nuHash());

$qry = "UPDATE echiplucrare SET echi_comanda_id = '$pk2' WHERE echiplucrare.echiplucrare_id = '$pk1';";
nuRunQuery($qry);

// The function afterDeleteRow() must be declared in the form's Custom Code 
$j = "afterDeleteRow();";
//nuJavascriptCallback($j);


In the custom code of subform FF6 I add this:

Code: Select all

function nuSelectBrowse(e){ 
        var r = $('#' + e.target.id).attr('data-nu-primary-key');
        nuSetProperty('ECHIPLUCRARE_ID', r);
        nuRunPHPHidden("AddCmd", 0);
        nuRunPHPHidden("AddCmd", 0);
        nuClosePopup();
    }

comanda1.jpg
I want to populate these fields one by one with record_id from the FF0 edit form
comanda2.jpg
Thanks, Gerese

Re: Custom code form - subform

Posted: Thu Nov 25, 2021 7:36 am
by kev1n
Hi gerese,

Is the update statement correct? Inspect it with nuDebug($sqry);

Re: Custom code form - subform

Posted: Thu Nov 25, 2021 8:59 am
by gerese
Hi Kev1n, is correct "update statement" but .... I fail to bring hash cookie "record_ID" of the editing form FF0 (nuSetProperty ('ECHI_COMANDA_ID', r1, 0);) in the procedure that must make the update statement that runs in subform FF6.

nuDebug (nuHash ()) - after running the Procedure does not contain hash cookie #ECHI_COMANDA_ID#

Code: Select all

[0] : Array
(
    [USER_ID] => globeadmin
    [USER_GROUP_ID] => 
    [HOME_ID] => nuhome
    [GLOBAL_ACCESS] => 1
    [ACCESS_LEVEL_CODE] => 
    [LOGIN_NAME] => globeadmin
    [USER_NAME] => 
    [USER_DEPARTMENT] => 
    [USER_TEAM] => 
    [USER_POSITION] => 
    [USER_ADDITIONAL1] => 
    [USER_ADDITIONAL2] => 
    [LANGUAGE] => Romanian
    [form_id] => 617efff03300f00
    [redirect_form_id] => 617efff03300f00
    [record_id] => 
    [title] => Fast Form 6
    [call_type] => 
    [column_widths] => 
    [filter] => 
    [forms] => 
    [iframe] => 0
    [lookup_id] => 
    [object_id] => 1
    [page_number] => 0
    [password] => 
    [rows] => 8
    [row_height] => 18
    [search] => 
    [session_id] => s16378231202823
    [nosearch_columns] => 
    [sort] => -1
    [sort_direction] => desc
    [subforms] => 0
    [tab_start] => 
    [username] => 
    [user_id] => globeadmin
    [refreshed] => 0
    [CLONED_RECORD] => 0
    [NEW_RECORD] => 0
    [redirect_other_form_id] => 
    [browse_columns] => 
    [browse_sql] => SELECT echiplucrare_id,echi_desc,echi_manifestare,str_1,amb_nr,comp_mic,echi_termen,luc_adresa_nr,luc_adresa_data,com_nr,com_data_start,echi_comanda_id
 FROM     echiplucrare         LEFT JOIN lucrare ON echiplucrare.echi_lucrare_id = lucrare.lucrare_id         LEFT JOIN comanda ON echiplucrare.echi_comanda_id = comanda.comanda_id         LEFT JOIN compartiment ON echiplucrare.echi_compartiment_id = compartiment.compartiment_id         LEFT JOIN ambarcatiune ON echiplucrare.echi_ambarcatiune_id = ambarcatiune.ambarcatiune_id         LEFT JOIN structura ON echiplucrare.echi_structura_id = structura.structura_id
WHERE 1
    [browse_rows] => 
    [browse_table_id] => ___nu1619f32a401ce1___
    [browse_filtered_rows] => 9
    [browse_title_multiline] => 1
    [pages] => 2
    [form_code] => FF6
    [form_description] => Fast Form 6
    [form_type] => browseedit
    [run_code] => 
    [run_description] => 
    [data_mode] => 
    [ECHIPLUCRARE_ID] => 61804cfa2b3e394
    [hash_record_id] => 
    [nuFORMdata] => Array
        (
            [0] => stdClass Object
                (
                    [id] => nuBuilder4EditForm
                    [foreign_key] => 
                    [primary_key] => echiplucrare_id
                    [object_id] => 617efff03300f00
                    [table] => echiplucrare
                    [action] => save
                    [rows] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 
                                    [1] => 0
                                )

                        )

                    [columns] => 
                    [chartData] => 
                    [chartDataPivot] => 
                    [edited] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 0
                                    [1] => 0
                                )

                        )

                    [deleted] => Array
                        (
                            [0] => 0
                        )

                    [fields] => Array
                        (
                            [0] => ID
                            [1] => nuDelete
                        )

                )

        )

    [hash] => 
    [ID] => 
    [nuDelete] => 0
    [PREVIOUS_RECORD_ID] => AddCmd
    [RECORD_ID] => AddCmd
    [FORM_ID] => doesntmatter
    [SUBFORM_ID] => 1
    [CODE] => 
    [TABLE_ID] => ___nu1619f32a622ed4___
    [SESSION_ID] => s16378231202823
)

Thanks, Gerese

Re: Custom code form - subform

Posted: Thu Nov 25, 2021 9:05 am
by kev1n
The issue might be here. nuSetProperty() sets the hash cookie for the current form only. So you might want to pass true as 3rd parameter to set a global hash cookie.

Code: Select all

  nuSetProperty('ECHI_COMANDA_ID', r1, true);

Re: Custom code form - subform

Posted: Thu Nov 25, 2021 10:04 am
by gerese
:shock: :shock: :shock: very simple .... thanks Kev1n

PS. I think I found a bug, I will explain in a new post.

Re: Custom code form - subform

Posted: Sat Nov 27, 2021 3:14 pm
by gerese
Hi again Kev1n, new issue

How can I refresh the FF0 edit form after the FF6 subform popup closes as a result of running the "AddCmd" procedure (Procedure that adds the foreign key)?
Update statement work great.

Thanks, Gerese

Re: Custom code form - subform

Posted: Sat Nov 27, 2021 3:40 pm
by kev1n
Instead of

Code: Select all

nuJavascriptCallback("nuClosePopup();");
refresh the parent form

Code: Select all

nuJavascriptCallback("parent.nuGetBreadcrumb()");

Re: Custom code form - subform

Posted: Sat Nov 27, 2021 4:07 pm
by gerese
:D Thanks man ... I am your fan