Updating Field of Subform after Selection on the first Field

Questions related to customising nuBuilder Forte with JavaScript or PHP.

Updating Field of Subform after Selection on the first Field

Unread postby SchHo » Sat Sep 11, 2021 5:23 am

Hi there,

I'm new into Nubuilder and pretty much like it. I'm currently building a databas including forms to ensure batch traceability in an small Food Production.
I have a Form for goods receipt. In this Ihave a Subform for the Items of the receipt. After Selecting the Good (Ware) in the Subform i'd like to have the Field for quantity unit (ME) updatedautomitically.

Based on some articles here in the Forum I tried to do the following:

1. Put this code on the onchange event of the employee select field

Code: Select all
getMEInfo(event);


2. In your form's Custom Code, add this code:

Code: Select all
function fillMEInfo(prefix, gqw_sf000gqp_mengeneinheit) {
     
        $('#' + prefix + 'gqw_sf000gqp_mengeneinheit').val(gqw_sf000gqp_mengeneinheit).change();  // replace 'gqw_sf000gqp_mengeneinheit' with your gqw_sf000gqp_mengeneinheit field object Id
       
    }

    function getMEInfo(event) {

        var MEId = $('#' + event.target.id).val();
        nuSetProperty('MEId', MEId);

        var prefix = $(event.target).attr('data-nu-prefix');
        nuSetProperty('prefix', prefix);

        nuRunPHPHidden('getMEInfo', 0)
    }

3. Create a PHP Procedure with the name getMEInfo

Code: Select all
function getMEInfo($ware_id) {
       
       // Change the SQL query here:
       // $sql = "SELECT war_mengeneinheit FROM `ware` WHERE `ware_id` = ?";
      $sql = "SELECT war_mengeneinheit FROM `ware` WHERE `ware_id` = 'gqw_sf000gqp_ware'";

        $qry = nuRunQuery($sql, [$ware_id]);
        $row = db_fetch_object($qry);

        return array(
            "gqw_sf000gqp_mengeneinheit" => $row->gqw_sf000gqp_mengeneinheit,  // replace gqw_sf000gqp_mengeneinheit with your sql column
           
        );
    }


    $empInfo = getMEInfo("#MEId#");

    $gqw_sf000gqp_mengeneinheit = $empInfo["gqw_sf000gqp_mengeneinheit"];
    $name = $empInfo["name"];
    $group = $empInfo["group"];

    $j = "fillMEInfo('#prefix#', '$gqw_sf000gqp_mengeneinheit'); ";

    nuJavascriptCallback($j);


This are my Tables:

1. gq_wareneingang (Table for Main Form)

Table 1.png
Table 1.png (20.07 KiB) Viewed 123 times


2. gqp_weposten (Table for Subform)

Table 2.png
Table 2.png (18.57 KiB) Viewed 123 times


3. Ware (Table where the Goods type is selected from and the ME-Field should be looked up from)

Table 3.png
Table 3.png (15.34 KiB) Viewed 123 times


I do not get any Errors on nuDebug.
Would be great, if anyone could help me here.
Thanks in advance,
Ralf
SchHo
 
Posts: 2
Joined: Sat Sep 11, 2021 4:50 am
nuBuilder Version: 4.5

Re: Updating Field of Subform after Selection on the first F

Unread postby steven » Sat Sep 11, 2021 7:47 am

Hi SchHo,

If you are using a Lookup to select your "Good" you can use PHP in the AfterBrowse for that Lookup to update the fields you can update...
https://wiki.nubuilder.net/nubuilderfor ... tFormValue

as.png
as.png (24.37 KiB) Viewed 120 times



Steven
steven
 
Posts: 138
Joined: Mon Jun 15, 2009 5:33 pm

Re: Updating Field of Subform after Selection on the first F

Unread postby SchHo » Thu Sep 16, 2021 2:56 am

Hi Steven,

thanks for your reply. I read about this Option an already tried it.
But still I feel, that the Lookup is not the right thing for me here, as it opens a new window and takes more time to find the right "Good"
to keep the form as simple as possible for the Users, I'd prefer a Select field.

Ralf
SchHo
 
Posts: 2
Joined: Sat Sep 11, 2021 4:50 am
nuBuilder Version: 4.5

Re: Updating Field of Subform after Selection on the first F

Unread postby kev1n » Thu Sep 16, 2021 11:57 pm

Hi Ralf,

Add debugger; in the function fillMEInfo() and keep the developer console (usually F12) open while selecting a value in your quantity unit (ME)

The debugger statement in JavaScript is used for setting a breakpoint in the code. The code stops execution as soon as it encounters the debugger statement.
This allows you to inspect the parameters prefix and gqw_sf000gqp_mengeneinheit to see if they contain any/the correct values.

Code: Select all
function fillMEInfo(prefix, gqw_sf000gqp_mengeneinheit) {

debugger;

/// other ode here...


And: What object types are you using for Good (Ware) and quantity unit (ME) ?
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5


Return to Custom Code

Who is online

Users browsing this forum: No registered users and 3 guests

cron