WebFOCUS write back function using Datatables Editor

WebFOCUS write back function using Datatables Editor

IMS_PeteIMS_Pete Posts: 21Questions: 4Answers: 0
edited March 2017 in Editor

Hi @Allan

As discussed a while back we integrate our datatable editor functionality with a reporting service called WebFOCUS which has some specific format requirements when defining variables to be passed between the browser client and the reporting server.

Key to this is a preSubmit function which flattens the variables being passed on submit. Example below:

function preSubmitFunction (e,d,a) { 
   for (p in d.data) {
      d['ROW_ID'] = p ;
      for (q in d.data[p]) {d[q] = d.data[p][q];}
   }
   delete d.data;
}

This method works well for an edit of a single row of data however if multiple rows are selected for edit; on submit only one row is sent for update naturally.

I have a solution in mind of creating a clone of the editor and having the preSubmit function each rows update information to the new editor and submit each in turn. This would then cancel the original multi row submit.

I was wondering if there was a better way to accomplish this. Would it be possible to update the editor code to add something like “editor.submit(d.data[p])” to the above function?

Replies

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin

    The best option would be to have the server-side accept a format that includes information for multiple rows. Is that possible?

    The code above intentionally flattens the data so it is only ever possible to submit one row - really you need to not flatten the data and have the server accept arrays / objects.

    Allan

  • IMS_PeteIMS_Pete Posts: 21Questions: 4Answers: 0

    Thanks @allan
    I created a proof of concept that handles the data-set on the server-side and successfully updates the database and returns the required response. It's not particularly pretty but it is working.
    I have some concerns that this would introduce some issues with users submitting exceptionally large amounts of data though. There is in theory no limit on the number of records this method can handle.

    I'll have a play with my clone method idea and see if I can come up with a more elegant client-side solution.

    Will try to share what I find.

  • IMS_PeteIMS_Pete Posts: 21Questions: 4Answers: 0

    So after a year of use we've not had any issues. I'll try to add the code we used below:

    First we need to prep the array for sending to WebFOCUS

     function prepData(e,d,a) {
     d = EncodeParameters(d)
     d['ROWID_LIST'] = '' ;
     for (p in d.data) {
       d['ROWID_LIST'] += '^' + p ;
       }
     }
    
    function EncodeParameters(d) {
      var stgValue = '' ;
       for (p in d.data) {
       for (q in d.data[p]) {
        stgValue = d.data[p][q];
        stgValue = stgValue.replace(/&/g, "&|") ;
        stgValue = stgValue.replace(/'/g, "''") ;
        d.data[p][q] = stgValue;
       }
       }
        return d
        }
    

    And the following is in WebFOCUS accessing the array

    -*ROWID_LIST format = "^ID1^ID2"
    -*Data Array Format = "data[ROW_ID][VARIABLE]:Value"
    
    -*************************** Work out the number of rows ***********************
    -SET &RowIdListLength = &ROWID_LIST.LENGTH;
    -SET &TmpRowIdString = STRREP(&ROWID_LIST.LENGTH,&ROWID_LIST,1,'^',0,FOC_NONE,&ROWID_LIST.LENGTH,'A4000');
    -SET &TmpRowIdString = TRUNCATE(&TmpRowIdString);
    -SET &RowsToEdit = &RowIdListLength - &TmpRowIdString.LENGTH;
    
    -************************** Set the fields you want to capture *******************
    -SET &FieldNameString1 = '][MyField1]' ;
    -SET &FieldNameString2 = '][MyField2]' ;
    -SET &FieldNameString3 = '][MyField3]' ;
    
    -************************** Loop through the rows and pull out the data *******
    -REPEAT :GetRow FOR &RowNo FROM 1 TO &RowsToEdit;
    -SET &IdTokenNumber = &RowNo + 1;
    -SET &RowID = TOKEN(&ROWID_LIST,'^',&IdTokenNumber.EVAL) ;
    
    -SET &FieldValue1Tmp = '&|data[' || &RowID || &FieldNameString1 ;
    -SET &FieldValue1= &FieldValue1Tmp.EVAL;
    -SET &FieldValue2Tmp = '&|data[' || &RowID || &FieldNameString2 ;
    -SET &FieldValue2= &FieldValue2Tmp.EVAL;
    -SET &FieldValue3Tmp = '&|data[' || &RowID || &FieldNameString3 ;
    -SET &FieldValue3= &FieldValue3Tmp.EVAL;
    
    -* Do something with the data
    
    -:GetRow
    
  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin

    Super - thanks for sharing that with us!

    Allan

This discussion has been closed.