Is it possible to UPDATE two different columns?

I've A, B, C, D columns E is auto increment
image

I'm able edit on D column row by this script

I would like also EDIT on A column row and I don't want to touch B,C columns row.
Is it possible or I should EDIT all columns ?

I show how to do this in my CRUDII guide:

// Edit/Update existing record, requires index/row and current col1 to match
  else if ( fn == 'UPDATE' ) {
    var index = e.parameter.INDEX;  //index in list
    var col1 = e.parameter.COL1;  // current/existing value of col1 - it could be replaced...
    var data = e.parameter.DATA.split(','); //new data
    var range = sh.getRange((parseInt(index)+1),1,1,data.length);
    for (var i = 0; i < rg.length; i++ ) {
      if ( index != undefined && i == index && col1 == rg[i][0] ) {
        range.setValues([data]);
      } 
    }
    return ContentService.createTextOutput("Record updated");    
    }

You send the script a comma separated list of the row values (after editing them) e.g.

e.parameter.DATA = "21/06", "000123","COLA 1L",10

then the script should do the rest

the script it's confusing me , is there any other options?

Develop your existing script to setValues() for columns 1 - 4, instead of just column D.
(it is a bit easier to overwrite columns you do not want to change with the same/existing values, as opposed to setting each cell individually with setValue()

Like this:

 //UPDATE TO TRUCK
     if (e.parameter.Action == "Update_Truck") { 
    var data =[[e.parameter.Date, e.parameter.Box]];
     sheet.getRange("A"+(parseInt(e.parameter.id)+1)+":D"+(parseInt(e.parameter.id)+1)).setValues(1-4); 
     return ContentService.createTextOutput("Success");
   }

I would like only update e.parameter.Date and e.parameter.Box
so setValue I out (1-4)
is it correct with script?

Not quite....

You first need to also provide the values you are not updating (these will just overwrite) e.g.

data = [[e.parameter.Date, eparameter.qrCode, e.parameter.item, e.parameter.Box]]

then your code to set the row items

sheet.getRange("A"+(parseInt(e.parameter.id)+1)+":D"+(parseInt(e.parameter.id)+1)).setValues(data);

Does this work for you ?

Also, for future help requests, please use the MIT App Inventor Help category, not General Discussion

IS it correct?

//UPDATE TO TRUCK
     if (e.parameter.Action == "Update_Truck") { 
    var data =[[e.parameter.Date, "'" + e.parameter.Qrcode, e.parameter.Item, e.parameter.Box]];
    sheet.getRange("A"+(parseInt(e.parameter.id)+1)+":D"+(parseInt(e.parameter.id)+1)).setValues(data); 
     return ContentService.createTextOutput("Success");
   }

Sure I'll thanks for remining

Did you try it ?

not yet
here in block

I guess you could also do it like this:

//UPDATE TO TRUCK
     if (e.parameter.Action == "Update_Truck") { 
    
    var newDate =[[e.parameter.Date]];
    sheet.getRange("A"+(parseInt(e.parameter.id)+1)).setValue(newDate); 

    var newBox =[[e.parameter.Box]];
    sheet.getRange("D"+(parseInt(e.parameter.id)+1)).setValue(newBox); 

     return ContentService.createTextOutput("Success");
   }
2 Likes

**

Working this is exactly what I wanted. Thank you so much @TIMAI2 :+1:

**

//UPDATE TO TRUCK
     if (e.parameter.Action == "Update_Truck") {
       
       var truck_date =[[e.parameter.Date]];
       sheet.getRange("A"+(parseInt(e.parameter.id)+1)).setValues(truck_date); 
       
       var truck_box =[[e.parameter.Box]];
       sheet.getRange("D"+(parseInt(e.parameter.id)+1)).setValues(truck_box); 
     
       return ContentService.createTextOutput("Success");
     }
1 Like

**Day by day Getting love with App inventor :smiling_face_with_three_hearts: :smiling_face_with_three_hearts: :smiling_face_with_three_hearts: **
Thank you so much Appinventor Team members for helping.
special thanks for @TIMAI2 @Spicy_Topics @dora_paz @SHUBHAMR69

2 Likes

this should be setValue() (no s at the end)

2 Likes

done, thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.