google apps script - Updating a field based on contents on another tab -
I have created a spreadsheet with several tabs.
The column 'id' and 'name' in my 'source' tab 1 have 'id' in my 'target' tab 2.
I am trying to iterate through rows in my Target tab and read the value of the ID and then search my source tab. Id. When I get the ID, I want to capture the value in the 'Name' field and I want to add it to a cell on the same line of ID of my Target tab.
I have a difficult time getting rid of the logic through an array and I'm getting the value in an array of the contents of the target tab or the target tab. In the Targets tab, there can be more than one instance of an ID, and I have to update them all.
Any suggestions will be welcome!
Here's a suggestion:
/ * Tell us source name With array (column A) & amp; The ID (column B) array is the 'source' and the target array in which the ID array is the 'target', you get it with something like * / var source = SpreadsheetApp.getActiveSpreadsheet (). GetSheets () [0] .getDataRange () GetValues (); // and var target = SpreadsheetApp.getActiveSpreadsheet (). GetSheets () [1] .getDataRange () GetValues (); // If the other column, change the index values in the array: 0 = A, 1 = B ... // Then create a third array, which will be the new target with the ID + names, and it will be 'newtarget' var newtarget = New Array () / call for I / L: i = 0; I & lt; Target.length; ++ i) {// (J = 0; J.L.L.; Source.Lamp; ++ J) does not remember any ID. I 0] .trastering (). Match (source [j] [1] .stisting ()) == source [ja] [1] .ststring ()) {var newtargetrow = [source [ja] [0], target [i] [0]] / / If the match was found, the name (idx0) and id (idx1)} and {var newtargetrow = ['no name found', target [i] [0]] // if not found match, in column of name Show} newtarget.push (newtargetrow); // store results in new array with 2 columns} // loop source} // loop targets * * Now you have a new target array that can directly overwrite the old target SetValues () * / Var sh = SpreadsheetApp.getActiveSpreadsh using Asset () GetSheets () [1]; // Target sheet as NR2 S.ZRRZ (1, newtabg.length, newtagues [0]. Length) .Setwolves (newtag); // Note that I did not test this code but it should give you a starting point I have compared it with a string, but you have other comparisons (direct parallel between array elements ) ... If you are in danger of unwanted spaces in sheet data then you can also remove spaces in the id ... I do not know your data, so it is up to you.
Comments
Post a Comment