Welcome to the nuBuilder Forums!

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

Updating Field of Subform after Selection on the first Field

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
SchHo
Posts: 2
Joined: Fri Sep 10, 2021 9:20 pm

Updating Field of Subform after Selection on the first Field

Unread post 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
You do not have the required permissions to view the files attached to this post.
steven
Posts: 370
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 53 times
Been thanked: 52 times

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

Unread post 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
You do not have the required permissions to view the files attached to this post.
A short post is a good post.
SchHo
Posts: 2
Joined: Fri Sep 10, 2021 9:20 pm

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

Unread post 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
kev1n
nuBuilder Team
Posts: 4302
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

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

Unread post 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) ?
Post Reply