Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By kleung
#827528
Hi,

I'm using PM 3.2.1 community version.
I would like to put the value of usrname and currentDtTm to the fields located at field 5 and field 6 of the grid gdCtrReg with the following Javascript.

$("#gdCtrReg").onAddRow(function(aNewRow, oGrid, rowIndex){
var usrname = $("#usrname").getValue() ;
var currentDtTm = $("#currentDtTm").getValue() ;
aNewRow[5].setValue(usrname) ;
aNewRow[6].setValue(currentDtTm) ;
}) ;

An interesting outcome is if I put the statement in the order above, the value of usrname can be inserted into field 5 properly but the value currentDtTm cannot be inserted into field 6.
If I swap the two statements, ie in the order
aNewRow[6].setValue(currentDtTm) ;
aNewRow[5].setValue(usrname) ;
the value of currentDtTm can be inserted into field 6 properly but usrname cannot be inserted to field 5.

Grateful if I can be advised what are the problems of my codes.

Many Thanks
cheers,
Karl
By ayodelebamgboye
#830533
The issue is could be the way the $("#currentDtTm").getValue() function is returning the value. It could be asynchronous, meaning that it may not be immediately available when the onAddRow function is executed.

a modified code below

$("#gdCtrReg").onAddRow(function(aNewRow, oGrid, rowIndex){
var usrname = $("#usrname").getValue();
getCurrentDtTm(function(currentDtTm){
aNewRow[5].setValue(usrname);
aNewRow[6].setValue(currentDtTm);
});
});

function getCurrentDtTm(callback) {
var currentDtTm = $("#currentDtTm").getValue();
if (currentDtTm) {
callback(currentDtTm);
} else {
setTimeout(function() {
getCurrentDtTm(callback);
}, 100);
}
}

ICO software script is a pre-made program for crea[…]

A crypto exchange script is a pre-designed softwar[…]

So I recently bought an addmotor Ebike which of co[…]

A crypto casino clone script is a ready-made softw[…]