Adding DAta To Grid

ProcessMaker code contributions

Moderator: amosbatto

sabinsunny
Posts: 22
Joined: Sat Feb 04, 2017 4:14 am
Country: India

Adding DAta To Grid

Unread postby sabinsunny » Tue Mar 28, 2017 8:01 am

Hi Team,

Please help Me,
i create a dyana form with some field what i need is i need to add all data i filled in form to grid.
once i added the forms must clear

here i attaching my two forms original php form and dyna form
Attachments
original form.jpg
PHP Form
original form.jpg (214.95 KiB) Viewed 2009 times
material.jpg
Dyna Form
material.jpg (115.9 KiB) Viewed 2009 times

amosbatto
Posts: 5334
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: Adding DAta To Grid

Unread postby amosbatto » Tue Mar 28, 2017 1:54 pm

I have prepared an example DynaForm which has JavaScript code to do this:
Add row to grid.json
(8.61 KiB) Downloaded 47 times


The Dynaform has the following fields:
AddRowToGridForm.png
AddRowToGridForm.png (22.9 KiB) Viewed 2003 times


The fields have the following IDs:

Code: Select all

1. Text: clientName
2. Dropdown: typeOfService
3. Checkbox: hasContract
4. Datetime: contractStartDate
5. Button: addToList
6. Button: clearList
7. Grid: clientsList
   with the following fields:
   1. Text: clientNameList
   2. Dropdown: typeOfServiceList
   3. Checkbox: hasContractList
   4. Datetime: contractStartDate


Then, add the following JavaScript to the DynaForm:

Code: Select all

$("#addToList").click( function() {
  var client = $("#clientName").getValue();
  var service = $("#typeOfService").getValue();
  var hasContract = $("#hasContract").getValue();
  var startDate = $("#contractStartDate").getValue();
  if (client == '') {
    alert("Please add a client name");
    return;
  }
  else if (hasContract == "1" && startDate == '') {
    alert("Please set the Contract Start Date");
    return;
  }
 
  var aData = [
    {value: client},
    {value: service},
    {value: hasContract},
    {value: startDate}
  ];   
  $("#clientsList").addRow(aData);

  //clear form:
  $("#clientName").setValue('');
  $("#typeOfService").setValue('');
  $("#hasContract").setValue('0');
 
  //workaround for clearing date fields:
  $("[id='form[contractStartDate]']").val('');
  $("[id='form[contractStartDate_label]']").val('');
  getFieldById("contractStartDate").model.attributes.data.label='';
  getFieldById("contractStartDate").model.attributes.data.value='';
});

function deleteList() {
  var oGrid = $("#clientsList"); //set to the ID of the grid
  var iRow = oGrid.getNumberRows();
  for (; iRow > 0; iRow--) {
     oGrid.deleteRow(iRow);
  }
}

$("#clearList").click(deleteList); //clear grid when clicking "clearList" button
deleteList(); //clear grid when the Dynaform loads

When the user clicks on the "clearList" button, the click event handler for the button checks whether the "clientName" textbox is empty and displays a message telling the user to fill the field. Likewise, if the user has marketd the "hasContract" checkbox, then the event handler checks whether the "contractStartDate" field is filled. There is a workaround to clear date fields, which won't be necessary in version 3.2 and later.
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

sabinsunny
Posts: 22
Joined: Sat Feb 04, 2017 4:14 am
Country: India

Re: Adding DAta To Grid

Unread postby sabinsunny » Wed Mar 29, 2017 6:09 am

WOWWWWW

its wORKING

sabinsunny
Posts: 22
Joined: Sat Feb 04, 2017 4:14 am
Country: India

Re: Adding DAta To Grid

Unread postby sabinsunny » Sun Apr 02, 2017 3:12 pm

hi,

now i can add data to grid view but in the next dynaform it not loading the data which i added in the grid,

first process adding data to grid in next level need to get appproval in approval form the grid value not loading

IF i manually adding data in the grid it shows on the next user

mishika
Posts: 156
Joined: Thu Feb 16, 2017 3:03 am
Country: India

Re: Adding DAta To Grid

Unread postby mishika » Mon Apr 03, 2017 7:49 am

Hello,

To avoid this problem, please make sure that you are not using any javascript in your second form which clears the grid data.
Like, if you have imported your first Dynaform again in the second Dynaform to verify, make sure you have modified the javascript that has come along with the Dynaform.
You can refer to the process I have attached below, which has 2 tasks where the first task has the Dynaform which gets the grid filled up and the second task has the Dynaform which verifies the grid data.

Hope this helps

Best Regards
Mishika
Attachments
grid_data-1.pmx
(45.23 KiB) Downloaded 43 times
Mishika

amosbatto
Posts: 5334
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: Adding DAta To Grid

Unread postby amosbatto » Mon Apr 03, 2017 9:20 pm

Remove this line from the JavaScript so that it doesn't automatically clear the grid:

Code: Select all

deleteList(); //clear grid when the Dynaform loads

It helps to read the code and try to understand what it is doing. ;-)
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

sabinsunny
Posts: 22
Joined: Sat Feb 04, 2017 4:14 am
Country: India

Re: Adding DAta To Grid

Unread postby sabinsunny » Wed Apr 05, 2017 1:03 am

i found that the issue is i uncheck the add row and delete row properties from grid properties now its working but not able to gemerate the value with grid
and i need support for report table and retrieve data to another form from report table

zainab
Posts: 237
Joined: Mon Dec 19, 2016 9:29 am
Country: India

Re: Adding DAta To Grid

Unread postby zainab » Wed Apr 05, 2017 3:13 am

Hello,

What support do you require regarding Report tables?

Kindly elaborate your scenario and we will help you with a solution.

Best Regards,
Zainab Sabunwala
Zainab

sabinsunny
Posts: 22
Joined: Sat Feb 04, 2017 4:14 am
Country: India

Re: Adding DAta To Grid

Unread postby sabinsunny » Wed Apr 05, 2017 5:24 am

Hi Team,

i have one process for creating material request, in that form i have one grid form am adding all data to that grid and sending to next user with the same table.

in next user he will create material request in SAP software and he will update the table with status is "closed".

process flow MATERIAL REQUEST --------------> SAP TEAM.

1) need to generate pdf with grid values (SAP TEAM)
2) need to store all data in report table (SAP TEAM dynaform)
3) need a form to view all my request and other request details also
Attachments
Create Material Request (1).json
(24.58 KiB) Downloaded 23 times
Adding Material.json
(6.58 KiB) Downloaded 23 times
123.png
Material REquest FORM
123.png (46.19 KiB) Viewed 1899 times
1.jpg
SAP TEAM FORM
1.jpg (70.28 KiB) Viewed 1899 times

zainab
Posts: 237
Joined: Mon Dec 19, 2016 9:29 am
Country: India

Re: Adding DAta To Grid

Unread postby zainab » Wed Apr 05, 2017 6:56 am

Hello,

For the first request, you can create an Output Document, and assign it after the second dynaform. Edt your Output document with the HTML editor and include the below code to display the grid along with the values:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<p align="center">SAP Report</p>
<p align="center"><span>@#creator_name @#employee_code </span></p>
<p align="left"></p>
<table cellspacing="0" border="1">
<tbody>
<tr><th>SAP Material Code</th><th>Material Description</th><th>Quantity</th><th>Unit</th><th>Building Name</th><th>Site</th><th>Parts</th><th>Floor</th><th>Note</th><th>Status</th></tr>
<[email protected]>gridVar-->
<tr>
<td>@#sapmc</td>
<td>@#materialdesc</td>
<td>@#Quantity</td>
<td>@#unit</td>
<td>@#buildingname</td>
<td>@#Site</td>
<td>@#Parts</td>
<td>@#Floor</td>
<td>@#Note</td>
<td>@#dropdown0000000001_label</td>
</tr>
<[email protected]<gridVar--></tbody>
</table>
</body>
</html>


In the settings of your Output Document, set the Properties according to your requirement, for example select .pdf if you want your Output document only in PDF format.

For your second requirement, it is better to create a separate PMT table in the database to store the grid values than using a Report table. Since grids contain multiple values, it is not easy to directly store grids in Report tables. The workaround for this would be to create a table PMT_SAPREPORT containing the fields of the grid along with the APP_UID which would store the Case Id. Then create the following trigger in your process, and set it to fire after the second task to store the values in database:

Code: Select all

$grid = @=gridVar;
foreach($grid as $row)
{
   $app = @@APPLICATION;
 $sapmc = $row['sapmc'];
   $material = $row['materialdesc'];
   $quantity = $row['Quantity'];
   $unit = $row['unit'];
   $building = $row['buildingname'];
   $site = $row['Site'];
   $parts = $row['Parts'];
   $floor = $row['Floor'];
   $note = $row['Note'];
   $status = $row['dropdown0000000001_label'];
   @@insert = executeQuery("INSERT INTO PMT_SAP(APP_UID,SAP,MATERIAL,QUANTITY,UNIT,BUILDING,SITE,PARTS,FLOOR,NOTE,STATUS) VALUES ('$app','$sapmc','$material','$quantity','$unit','$building','$site','$parts','$floor','$note','$status')");
}

If you want to store data from other fields, you can include them as well.

Please let us know if you have further doubts.

Hope this helps.

Best Regards,
Zainab Sabunwala
Zainab

sabinsunny
Posts: 22
Joined: Sat Feb 04, 2017 4:14 am
Country: India

Re: Adding DAta To Grid

Unread postby sabinsunny » Wed Apr 05, 2017 9:55 am

wow thanks its working but when i add trigger am getting error mysql stoped and not able to restart then i need to restore the PM Backup

in the report database i need to add
1
case no
2
project name , serial no, project)no, date of creation , and the pdf

sabinsunny
Posts: 22
Joined: Sat Feb 04, 2017 4:14 am
Country: India

Fetching value to dynaform from report

Unread postby sabinsunny » Mon Apr 10, 2017 7:22 am

Hi Team,
Is it possible to fetch data from report table to dynaform
i need to fetch datas like
opend case no
case creator name
case status

mishika
Posts: 156
Joined: Thu Feb 16, 2017 3:03 am
Country: India

Re: Adding DAta To Grid

Unread postby mishika » Mon Apr 10, 2017 7:56 am

Hello,

Yes, it is possible to fetch the data from Report table for the current case. There are certain points to be kept in mind:

1. The entry in a Report table for the case is created in the first task before routing. So, if you want to fetch the data for the current case in the first task, you can access it using the system variable @@APPLICATION(using the table APPLICATION from the database) instead of getting it from the Report table.
2. To fetch data from Report table before Dynaform, you can create a trigger which runs a SELECT query in the report table and gets the data in a variable of the process. This trigger can be placed before the Dynaform and the variable which has been used to store the table's data can be used directly in the Dynaform. You can refer the following trigger:

Code: Select all

$query = "SELECT * FROM PMT_GRIDS";
@@res = executeQuery($query);
@@appnumber = @@res[1]['APP_NUMBER'];


3. Also, you will get the Case number, Case status, and Case UID from the Report table and not the Case creator's name.
So, you can use the APPLICATION table to do so (column APP_INIT_USER).

Hope this helps

Best Regards
Mishika
Mishika

sabinsunny
Posts: 22
Joined: Sat Feb 04, 2017 4:14 am
Country: India

Re: Adding DAta To Grid

Unread postby sabinsunny » Tue Apr 11, 2017 2:16 am

hi team, thanks for supporting me,

my idea is simple i need to create a process for report view
in dyna form i need to load all data grid
like case no case creator app_status ..etc

i tried with simple sql code its working but issue the code is loading only one row values i have 100 rows in my report table

mishika
Posts: 156
Joined: Thu Feb 16, 2017 3:03 am
Country: India

Re: Adding DAta To Grid

Unread postby mishika » Tue Apr 11, 2017 2:52 am

Hello,

To achieve your requirement, please refer the process I have attached here.
The process has the following:
1. A report table which includes all the field of a Dynaform in the process.
2. Another Dynaform has a grid which displays the data from the report table.
3. A trigger which fires a SQL query to fetch the data from the report table from the database.
Make sure that the column Id of the grid is same as the field names in your report table. You can also use the alias to do so.
If the field names are different than the column ids, the array fetched from the SQL query will not match to the grid's value.

Hope this helps

Best Regards
Mishika
Attachments
report_table_data-1.pmx
(38.46 KiB) Downloaded 51 times
Mishika


Return to “Code”

Who is online

Users browsing this forum: No registered users and 1 guest