Page 2 of 2
Re: PHP after browse in select object
Posted: Sat Jul 15, 2023 3:52 pm
by yvesf
DET_TYPE_ID is an object. I have tried in smaller case.
Here is a screenshot of this object id
CCSelect.PNG
and the related procedure in which I should retrieve the value of det_type_id object.
procRecup.PNG
And the result in nuDebug
nuDeBUG.PNG
I don't see a solution
Many thx,
Yves
Re: PHP after browse in select object
Posted: Sat Jul 15, 2023 4:00 pm
by kev1n
Can you show a screenshot of the table schema?
Re: PHP after browse in select object
Posted: Sat Jul 15, 2023 6:17 pm
by yvesf
Here is the schema.
Detail is a subform of Acte browse and edit form
Type is a browse and edit form
Schema.PNG
Many thanks,
Yves
Re: PHP after browse in select object
Posted: Sat Jul 15, 2023 6:20 pm
by yvesf
Here is a backup of the database :
07-15-2023_151920_64b2c70872c87_nuBuilder_backup.sql.gzip
Re: PHP after browse in select object
Posted: Sun Jul 16, 2023 12:51 am
by yvesf
If we are not in a subform, your solution works without any pb.
-->
Video_2023-07-16_004454.gif
with behind the custom code of the act_activities object
and procedure Montant as following :
Code: Select all
$s = "SELECT aty_montant FROM activity WHERE aty_code = ?";
$t = nuRunQuery($s, array('#act_activities#'));
if (db_num_rows($t) == 1) {
$r = db_fetch_object($t);
$js= "nuSetValue('act_montant', $r->aty_montant);";
nuJavaScriptCallback($js);
}
But if we are in a subform, it doesn't work unfortunately.
If you could help.
Yves
Re: PHP after browse in select object
Posted: Sun Jul 16, 2023 8:01 am
by kev1n
In the subform, each object in a row has a unique ID. You can first set a hash cookie containing the value of the select object. Then, proceed to call the 'nuRunPHPHidden()' function.
Code: Select all
nuSetProperty('det_type_id', this.value);
nuRunPHPHidden('RecupMontant', 0);
Re: PHP after browse in select object
Posted: Sun Jul 16, 2023 9:05 am
by yvesf
Great thanks, with this approach, I can effectively pass the value to the subform. But in the procedure, how can I know the unique ID of the object corresponding to det_montant ? I have also to pass this value to the procedure at the same time as you set the det_type_id hash cookie.
How can I do that ?
In Custom code
Code: Select all
nuSetProperty('det_type_id', this.value);
nuSetProperty('det_montant', nuGetValue('det_montant'));
nuRunPHPHidden('RecupMontant', 0);
In the related procedure RecupMontant
Code: Select all
$s = "SELECT type.typ_montant FROM type where type.typ_code = '#det_type_id#'";
$t = nuRunQuery($s, array('#det_type_id#'));
if (db_num_rows($t) == 1) {
$r = db_fetch_object($t);
$js="nuSetProperty('det_montant',$r->typ_montant);";
nuJavaScriptCallback($js);
}
The assignment doesn't work even if I put nuSetValue instead of nuSetProperty. Many thanks for your help.
Yves
Re: PHP after browse in select object
Posted: Sun Jul 16, 2023 9:14 am
by kev1n
Also pass the ID of det_montant to php by setting an hash cookie in JS:
Code: Select all
const montantId = nuSubformRowObject(this.id, 'det_montant').attr('id');
nuSetProperty('montantId', montantId);
In PHP, retrieve it like this:
Code: Select all
$js= "nuSetValue('#montantId#', $r->aty_montant);";
Re: PHP after browse in select object
Posted: Sun Jul 16, 2023 9:35 am
by yvesf
Great thanks Kev1n !!!

It effectively works as expected. What a such work to do that in subform !!! But it works perfectly.
Yves