Page 1 of 1

Updating Field of Subform after Selection on the first Field

Posted: Fri Sep 10, 2021 9:53 pm
by SchHo
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
2. gqp_weposten (Table for Subform)
Table 2.png
3. Ware (Table where the Goods type is selected from and the ME-Field should be looked up from)
Table 3.png
I do not get any Errors on nuDebug.
Would be great, if anyone could help me here.
Thanks in advance,
Ralf

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

Posted: Sat Sep 11, 2021 12:17 am
by steven
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.cloud/ ... tFormValue
as.png

Steven

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

Posted: Wed Sep 15, 2021 7:26 pm
by SchHo
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

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

Posted: Thu Sep 16, 2021 4:27 pm
by kev1n
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) ?