Page 1 of 1

Fetch and display content in PM Table on Dynaform

Posted: Wed Jan 23, 2019 10:44 pm
by shuqierduo
All, I understand that this could be a dummy question but I could not find answers from the documentation nor forum, maybe I am searching the wrong keywords...

I have a PM Table "Customer" created with autogen customer ID and other demographics as attributes (e.g. name, address, etc.)

On a process:

Step 1 To display selected fields of the Customer table and have user to select one of customer
Step 2 For selected customer, show a form with all customer attributes for editing and save the edits back to PMTable

Can you shed some lights on how it can be done? I am stuck on the first step to even display the records on a form.

Many thanks.

Re: Fetch and display content in PM Table on Dynaform

Posted: Thu Jan 24, 2019 1:05 am
by amosbatto
This documentation for version 2 also works for version 3:
https://wiki.processmaker.com/index.php ... base_Query

If you can't figure it out, then post the .json file for our dynaform, your trigger code and a screen shot of your PM Table's structure.

Re: Fetch and display content in PM Table on Dynaform

Posted: Fri Jan 25, 2019 11:59 am
by shuqierduo
Thanks. I have created a trigger with code below which the name of the grid on the Dynaform is customerGrid

$sql = "SELECT CUSTOMERID, CUSTOMERNAME FROM PMT_CUSTOMER";
@=customerGrid = executeQuery($sql);


The customer table contains other attributes besides ID and name.

To complete the mission, I would like to allow the user to select one customer record on the grid and proceed the next form, which display all customer attributes for editing.

Any suggestion on how that can be done?

Thanks a lot!

Re: Fetch and display content in PM Table on Dynaform

Posted: Fri Jan 25, 2019 7:22 pm
by amosbatto
Here is an example showing how to edit grid rows in subforms:
https://www.pmusers.com/index.php/Edit_ ... n_subforms

You will need a trigger before the form containing a grid to populate the grid (which you already have).
Then you will need another trigger afterwards to write the changes to the PM Table like this:
Code: Select all
foreach (@=chemicalList as $aRow) {
    $id = (int) $aRow['id']; //assuming that the ID field is an integer
    $name  = mysql_real_escape_string($aRow['name']);
    $desc  = mysql_real_escape_string($aRow['description']);
    $price  = (float) $aRow['price'];

    if (empty($aRow['id'])) {
        //assuming that the ID field is an auto increment field, that will automatically be inserted in the PM Table.
        $sql = "INSERT INTO PMT_CHEMICALS (NAME, DESCRIPTION, PRICE) VALUES ('$name', '$desc', $price)";
    }
    else {
        $sql = "UPDATE PMT_CHEMICALS SET NAME='$name', DESCRIPTION='$desc', PRICE=$price WHERE ID=$id";  
    }
   @@returnVal = executeQuery($sql);
}
Note: if you are using PHP 7, then use mysqli_real_escape_string().

Re: Fetch and display content in PM Table on Dynaform

Posted: Fri Jun 14, 2019 1:18 am
by HeshanKaru1994
Can you print a grid which is scrollable

Re: Fetch and display content in PM Table on Dynaform

Posted: Fri Jun 14, 2019 5:54 pm
by amosbatto
HeshanKaru1994 wrote:Can you print a grid which is scrollable
If you set the "layout" property of the grid to "static", then you can horizontally scroll to see wider grid rows.

There is no vertical scroll. You can set the "page size" property to limit the size of the grid.

The other option is to use an external library such as ParamQuery to display your grid in a Panel, but that requires making an array with the grid's contents, then using json_encode() to convert it to a string that can be set to a variable which is associated with a hidden field in the Dynaform. Then add JavaScript which uses JSON.parse( ) to convert the hidden field's string into an array which will display the grids contents.

When the Dynaform is submitted, convert the contents of the grid back to a JSON string to save in the hidden field.

Re: Fetch and display content in PM Table on Dynaform

Posted: Fri Jun 14, 2019 8:48 pm
by HeshanKaru1994
Any sample process?

Re: Fetch and display content in PM Table on Dynaform

Posted: Mon Jun 17, 2019 6:35 pm
by amosbatto
HeshanKaru1994 wrote: Fri Jun 14, 2019 8:48 pm Any sample process?
See:
viewtopic.php?f=44&t=736737&p=824742&hi ... ry#p824742