Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#821961
hello to all, please your help to resolve this doubt.

I have a dynaform that contains a variable called "correlativo", in javascript I have the function change.
see attach file change.png

whe value change or focus, this call the api to execute a trigger, see attach file correlativoTrigger.png

the problem is when the trigger is executed does not obtain the value of the variable called "correlative" of the dynaform in execution.

note: the trigger was assigned before and after executing the dynaform, but when these actions are performed the dynaform is still running

plz ur help.

regards.
Attachments
correlativoTrigger.png
trigger
correlativoTrigger.png (56.07 KiB) Viewed 2286 times
change.png
javascript code
change.png (110.73 KiB) Viewed 2286 times
#821972
It would be much easier to do this with a dependent field which will store the result of your SQL query. Create a text field whose ID and variable is "correlativoResult". Then set its "sql" property to:
SELECT CORRELATIVO, CORRELATIVO FROM PMT_RPT_TBL_INGRESO WHERE CORRELATIVO=@@correlativo LIMIT 1


If you don't want the user to see this text field, then you can use JavaScript to hide it:
Code: Select all
$("#correlativoResult").hide();
(Do not use a hidden field because hidden fields don't work as dependent fields.)

The other option is to use a suggest box where the user can only select an option found in the database. See this example:
viewtopic.php?f=44&t=731004&p=816153#p816153


I don't recommend using a trigger and using Javascript to execute REST endpoints, but I will explain why it didn't work.
1. Your PMT_RPT_TBL_INGRESO.CORRELATIVO is probably a char or varchar field, so you need to enclose it in single quotes ('value').
PS: If you set debug=1 in your env.ini file, MySQL error messages will be set in the @@__ERROR__ system variable which you can see if you turn on your process debugger.

2. The executeQuery() function has problems dealing with back ticks (`table`), so don't use them.

3. The value of @@correlativo is not yet saved to the database, so the trigger can't access it. You also can't use echo to set the response from the trigger.

You need to use this trigger code:
Code: Select all
$txt_busqueda = @@correlativo;
$sql = "SELECT CORRELATIVE FROM PMT_RPT_TBL_INGRESO WHERE CORRELATIVO = 
txt_busqueda limit 1";
$response = executeQuery($sql);
@@correlativoResult = '';
if (!empty($response)) {
   @@correlativoResult = $response['1']['CORRELATIVO'];
}
With JavaScript you will need call your REST endpoints in this order:
First, call PUT /cases/{app_uid}/variables to save the @@correlativo variable to the case in the database.
Second, call PUT /cases/{app_uid}/execute-trigger/{tri_uid} to execute the trigger.
Third call GET /cases/{app_uid}/variables to get the value of the @@correlativoResult variable from the database.


PS: If you have a question about code in the future, please post it as text, and not as images. Thanks.

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]