Just when I though I was getting better with my code, I realize how much there is to learn.
I have a simple grid where users add new data to several fields in a record. In this case, they are keeping records for Surveillance Cameras installed in their stores. Typically, they do the installation in a single day, using the same brand of cameras, with similar Serial #'s and "asset ID Tags". Here are some fields they'll be entering:I want to save them some data entry time by copying as much information as possible into the "new record", after they Submit. I've reviewed Alpha's M8 Video, which should work exactly the way I want it to, but it's not working for me. At first, I thought it was because I was using a "columnar grid" (not a single record form), but, even when I tried creating a form grid, I didn't get what I wanted. Because I'm using "rowNumber -1" it should work on the new record of any type of grid.
I was hoping someone could look at the code below and tell me what I'm doing wrong OR show me a better way to do it (I thought I read that there's a "Previous()" function in Alpha 12, but I couldn't find information about what it does or how to use it).
Here's what I put in the AfterInsertRecord (Server Side) to update the MfgSerNum field:
Then, in the Client Side "afterRowPopulate" section, here's what I added:
It seems like this should work, BUT it doesn't (if I leave the field's "Initial Value" to NULL, and submit a record with new data, the subsequent new record's field is NULL... If I set an initial value to "123ABC", and submit a record with new data, the subsequent new record's field is "123ABC" (no matter what the previous record had). I've tried so many variations and checked my code and I just can't figure it out.
Ultimately, if I get this solved, I'd love to be able to pre-populate the next record with a "sub-string" of the captured field (e.g. "Left(IPAddress,12)" or "Left(MfgSerNum,9)", etc.) in addition to the full "InstallDate" field.
Hopefully, someone will have some suggestions for me... I'd appreciate any help.
Phil
I have a simple grid where users add new data to several fields in a record. In this case, they are keeping records for Surveillance Cameras installed in their stores. Typically, they do the installation in a single day, using the same brand of cameras, with similar Serial #'s and "asset ID Tags". Here are some fields they'll be entering:
- InstallDate
- EquipmentIDNum
- IPAddress
- MfgSerNum
I was hoping someone could look at the code below and tell me what I'm doing wrong OR show me a better way to do it (I thought I read that there's a "Previous()" function in Alpha 12, but I couldn't find information about what it does or how to use it).
Here's what I put in the AfterInsertRecord (Server Side) to update the MfgSerNum field:
function AfterInsertRecord as v (e as p)
dim js as c
dim ar as p
ar.SerNum = e.dataSubmitted.MfgSerNum
dim json as c
json = vartojson(ar,.f.,.t.)
js = "{grid.object}.setStateInfo(" + json + ");"
e.rtc.A_AjaxResponses[].text = js
e.rtc.A_AjaxResponses[..].id = 1
end function
dim js as c
dim ar as p
ar.SerNum = e.dataSubmitted.MfgSerNum
dim json as c
json = vartojson(ar,.f.,.t.)
js = "{grid.object}.setStateInfo(" + json + ");"
e.rtc.A_AjaxResponses[].text = js
e.rtc.A_AjaxResponses[..].id = 1
end function
(NOTE: Using a "Debug(1)" command, I've verified that "ar" does, indeed, capture the Serial #)
Then, in the Client Side "afterRowPopulate" section, here's what I added:
//Determine if you're entering a "new" row
if(e.rowNumber == -1 ) {
//create a variable to the "SerNum" that was previously set
var newvalue = this.stateInfo.SerNum;
//Name an element variable to the field on the grid
var ele = $('{Grid.ComponentName}.V.R.'+e.rowNumber+'.MFGSERNUM');
//Set the value of "ele" to the "newvalue" variable
ele.value = newvalue;
}
if(e.rowNumber == -1 ) {
//create a variable to the "SerNum" that was previously set
var newvalue = this.stateInfo.SerNum;
//Name an element variable to the field on the grid
var ele = $('{Grid.ComponentName}.V.R.'+e.rowNumber+'.MFGSERNUM');
//Set the value of "ele" to the "newvalue" variable
ele.value = newvalue;
}
It seems like this should work, BUT it doesn't (if I leave the field's "Initial Value" to NULL, and submit a record with new data, the subsequent new record's field is NULL... If I set an initial value to "123ABC", and submit a record with new data, the subsequent new record's field is "123ABC" (no matter what the previous record had). I've tried so many variations and checked my code and I just can't figure it out.
Ultimately, if I get this solved, I'd love to be able to pre-populate the next record with a "sub-string" of the captured field (e.g. "Left(IPAddress,12)" or "Left(MfgSerNum,9)", etc.) in addition to the full "InstallDate" field.
Hopefully, someone will have some suggestions for me... I'd appreciate any help.
Phil
Comment