Page 1 of 1

Can make a SQL server query from PM trigger?

Posted: Thu Aug 01, 2019 11:34 am
by FreddyBernal
Hi,
I need get some information from SQL Server, if I install Microsoft ODBC Driver for SQL Server in Linux, can use it in a trigger?
I have some information in SQL Server that need get using as key a form field in PM.
Some suggestions?

Regards,

Fred

Re: Can make a SQL server query from PM trigger?

Posted: Fri Aug 02, 2019 12:23 am
by amosbatto
Follow the instructions on the wiki:
https://wiki.processmaker.com/3.3/Datab ... ions/MSSQL

The instructions aren't complete if you are using ProcessMaker installed in Windows.
The php_dblibx64.dll library only works if you are using PHP 5.6. Please go to Admin > System Information in ProcessMaker to verify which version of PHP you are using.

If you are using PM 3.3.0 or later with PHP 7.0 or later in Windows, then you need to follow these instructions to install
the SQLSRV and PDO_SQLSRV drivers:
https://docs.microsoft.com/en-us/sql/co ... erver-2017

Here is the page to download the files:
https://www.microsoft.com/en-us/downloa ... x?id=57916

After you have installed the PHP files for MSSQL, then you can create a Database Connection that connects to your installation of MSSQL. Then, you can use the ID of the Database Connection when calling the executeQuery() function in a trigger.

Re: Can make a SQL server query from PM trigger?

Posted: Fri Aug 02, 2019 8:13 am
by FreddyBernal
Thank you!!!
But if I have to make a query using data from a field in Dynaform (in a click botton of another event), how can do it?

Regards

Re: Can make a SQL server query from PM trigger?

Posted: Fri Aug 02, 2019 10:25 pm
by amosbatto
The easiest way to use the value from a Dynaform field in your SQL query is to use a dependent field.

The dependent field query will automatically happen when the value of the independent field changes.
For example, if your SQL query is:
SELECT CLIENT_ID, CLIENT_NAME FROM CLIENTS WHEN COUNTRY=@@selectCountry

Then, the query will happen automatically when the value of the "selectCountry" field changes.

If you want to do this the hard way and control this with the click of a button, then you can use jQuery's $.ajax() function to call the following REST endpoint:
POST project/{prj_uid}/process-variable/{var_name}/execute-query-suggest

See this example of how to call REST with JavaScript:
https://wiki.processmaker.com/3.2/JavaS ... ing_jQuery

To populate the list of options with JavaScript, see:
https://www.pmusers.com/index.php/Chang ... tions_list