This pertains within a BPM application called ProcessMaker but the logic and syntax should relatively be the same. I’m trying to
populate a grid (basically a table) from another serialized grid where the data has been passed to a hidden field.
The data passed to the hidden field is formatted as follows:
Ex:
{"1":{"id":"4332","product":"ball","price":"$5.00",”ordered":"On"}
The javascript example below found on processmaker’s wiki unserializes the hidden field as an object and uses its information to populate a new grid named whatever it is. The example on processmaker’s wiki uses the eval function but how would you convert this using the json.parse() function?
function populateGrid() {
var grd = getObject("newAccountsGrid");
//remove all existing rows in the grid (except the first one):
var i = Number_Rows_Grid("newAccountsGrid", "accId");
for (; i > 1; i--)
grd.deleteGridRow(i, true);
//The first row can't be deleted, so clear the fields in the first row:
for (i = 0; i < grd.aFields.length; i++)
getGridField("contactsGrid", 1, grd.aFields[i].sFieldName).value = "";
//unserialize the hidden field as an object:
var oAccounts = eval('(' + getField("sAccounts").value + ')');
if (typeof oAccounts == 'object') {
for (var rowNo in oAccounts) {
if (rowNo != 1)
grd.addGridRow();
getGridField('newAccountsGrid', rowNo, 'accId').href = oAccounts[rowNo]["accountId"];
getGridField('newAccountsGrid', rowNo, 'accName').href = oAccounts[rowNo]["accountName"];
getGridField('newAccountsGrid', rowNo, 'createDate').href = oAccounts[rowNo]["created"];
}
}
}
populateGrid(); //execute when the DynaForm loads
It would be as simple as: