Page 1 of 1

How to make a grid column value be displayed in a text box?

Posted: Fri Jun 08, 2012 3:14 pm
by obynoreg1
I just started 2 days ago to work with Processmaker and I am confused as to how to make a text box value on a normal form be populated onto the grid form. Also, How do I change the "Σ = " to "Process Total value=" in the grid form.

Thanks

Re: How to make a grid column value be displayed in a text b

Posted: Fri Jun 08, 2012 5:36 pm
by amosbatto
Here is some code to do those things:
Code: Select all
var dynaformOnload = function() {
   //set value for the first row:
   getGridField("MyGrid", 1, "MyField").value = getField("someField").value;

  //set value for all subsequent rows that are added dynamically:
  grid_MyGrid.onaddrow = function(iRow) {
      getGridField("MyGrid", iRow, "MyField").value = getField("someField").value;
  }

  //replace  sum sign:
  var nCol = 2; //set to the index of the column which has the sum sign
  var gridName = "mygrid"; //set to the name of the grid
  var nLastRow = document.getElementById(gridName).rows.length - 1;
  document.getElementById(gridName).rows[nLastRow].cells[nCol].innerHTML =
     document.getElementById(gridName).rows[nLastRow].cells[nCol].innerHTML.replace('Σ', 'Sum');
}
see:
http://wiki.processmaker.com/index.php/ ... ding_a_Row

Edited to change "var dynaformOnload = function()" to "var dynaformOnload = function() {"

Re: How to make a grid column value be displayed in a text b

Posted: Mon Jun 11, 2012 10:26 am
by obynoreg1
Please can you help walk me through the steps? I added a jaavscript object and then added the javascript to it. Do I need to call the script using trigger method or how do i go about doing it?

Thanks.

Re: How to make a grid column value be displayed in a text b

Posted: Mon Jun 11, 2012 10:46 am
by obynoreg1
I was getting this error "getGridField("TestGrid1", 1, "JobNumber") is null"

Re: How to make a grid column value be displayed in a text b

Posted: Mon Jun 11, 2012 9:10 pm
by amosbatto
Oh, I see an error in my code. Change "var dynaformOnload = function()" to "var dynaformOnload = function() {"

That should force the code to execute only after the dynaform has finished loading. The other problem could be that you misspelled the name of your grid or the name of the field. Remember that it is case sensitive. Also remember to use the name of the grid obect, which is embedded in the master form. Do not use the name of the grid form. If you don't know what I mean, post the XML for your form and I can tell you the correct name of the field to use in the function.

Re: How to make a grid column value be displayed in a text b

Posted: Tue Jun 12, 2012 10:07 am
by obynoreg1
It worked but I also wanted to display the value of the "Sum" to a text box. How do I do that assuming that I added a text box named "Total". All the text box does is to display the total amount that was calculated from the Sum in the grid and when there are some changes, it should update based on the amount that the Sum is holding.

Re: How to make a grid column value be displayed in a text b

Posted: Tue Jun 12, 2012 10:25 am
by obynoreg1
<name type="text" maxlength="64" validate="Any" required="0" readonly="1" size="15" mode="view" btn_cancel="Cancel" mask="" strto="" dependentfields="" defaultvalue="" hint="" formula="" function="" sqlconnection="" savelabel="0">
<en>Name</en>
</name>
<Date type="text" maxlength="64" validate="Any" required="0" readonly="0" size="15" mode="view" btn_cancel="Cancel" mask="" strto="" dependentfields="" defaultvalue="" hint="" formula="" function="" sqlconnection="" savelabel="0">
<en>Date</en>
</Date>
<JobNumber1 type="text" maxlength="64" validate="Any" required="0" readonly="0" size="15" mode="edit" btn_cancel="Cancel" mask="" strto="" dependentfields="" defaultvalue="" hint="" formula="" function="" sqlconnection="" savelabel="0">
<en>JobNumber</en>
</JobNumber1>
<AddTest type="text" maxlength="64" validate="Real" required="0" readonly="1" size="15" mode="edit" btn_cancel="Cancel" mask="" strto="" dependentfields="" defaultvalue="0" hint="" formula="" function="" sqlconnection="" savelabel="0">
<en>Total Reimbursement</en>
</AddTest>
<Total type="javascript"><![CDATA[var dynaformOnload = function() {
total = 0;
//set value for the first row:
getGridField("TestGridd", 1, "Value2").value = getField("AddTest").value;

//set value for all subsequent rows that are added dynamically:
grid_TestGridd.onaddrow = function(iRow) {
getGridField("TestGridd", iRow, "Value2").value = getField("AddTest").value;
total += parseFloat(getGridField("TestGridd", iRow, "Value2").value);
getField("AddTest").value = total;
}


//replace sum sign:
var nCol = 3; //set to the index of the column which has the sum sign
var gridName = "TestGridd"; //set to the name of the grid
var nLastRow = document.getElementById(gridName).rows.length - 1;
document.getElementById(gridName).rows[nLastRow].cells[nCol].innerHTML =
document.getElementById(gridName).rows[nLastRow].cells[nCol].innerHTML.replace('Σ', 'Total Reimbursement');
}]]></Total>
<TestGridd type="grid" xmlgrid="4354301434fce06ffd24bf6025751946/6719645254fd227950bce60003405414" addrow="1" deleterow="1" btn_cancel="Cancel"/>
<CurUser type="hidden" mode="edit" btn_cancel="Cancel"> </CurUser>
<CurNum type="hidden" mode="edit" btn_cancel="Cancel"> </CurNum>
<Add type="button" onclick="" btn_cancel="Cancel" required="0" readonly="0" savelabel="0">
<en>Add New</en>
</Add>
<Save type="button" btn_cancel="Cancel" onclick="Saves" required="0" readonly="0" savelabel="0">
<en>Save</en>
</Save>
<Saves type="javascript"><![CDATA[function saveIt() {
var url = location.href.substring(0, location.href.lastIndexOf('/')) + "main" + "/caseListExtJS";
saveAndRedirectForm("", url);
//window.location.href = "https://192.168.0.192/sysworkflow/en/cl ... eListExtJS";
}
getField("Save").onclick = saveIt;]]></Saves>
<___pm_boot_strap___ type="javascript" meta="s8jd"><![CDATA[/* @! Autogenerated by Processmaker weboot; Do not modify this content, this is autogenerated alway when dynaform is updated */ hideRowById('Add'); ]]></___pm_boot_strap___>