私はかなり初心者のプログラマーです。 formSubmitイベントで簡単な「ステータス変更」をしようとしています。私の旅の助けや援助に感謝します。Googleシートのステータス列を変更する方法参照番号
ユーザーがフォーム(https://docs.google.com/a/gregbartonmba.com/forms/d/e/1FAIpQLSccMrgAWq95SOJO-1TC74lb4ri71aZzIWCMe342KmM66d6lqw/viewform)を入力すると、スクリプトが実行されます。 - ReferenceNumberを含む参照行を検索します(B列)。 - ステータス列(列A)の値を新しいステータスに変更します。
私は修正しようとしたいくつかのサンプルコードを持っていますが、それを正しく取得するにはあまりにも多くの初心者です。私は近くにいると思うが、いくらか失われている...ありがとう。
コードのシートをここで見つけることができます: 私のコーディングの試みは、以下の投稿https://docs.google.com/spreadsheets/d/1yXIggGwWg84CebcABTLxPcCd8YI7W7VJL7PmVkcjvJI/edit?usp=sharing
...
function changeStatus(e) {
var Status = e.values[0];
var ReferenceNumber = e.values[1];
// Look up the cell in the sheet that contains the ReferenceNumber.
// Find the instance in range B2:B that has the ReferenceNumber entered.
// Then, change the code of the left-most cell (Status) to the new "Status" (entered from form submission)
/* Modified code from example at:
http://stackoverflow.com/questions/18482143/google-scripts-search-spreadsheet-by-column-return-rows
*/
var searchString = ReferenceNumber;
var ss = SpreadsheetApp.openById("1yXIggGwWg84CebcABTLxPcCd8YI7W7VJL7PmVkcjvJI");
var column =1; //column Index
var columnValues = ss.getRange(2, column, ss.getLastRow()).getValues(); //1st is header row
var searchResult = columnValues.findIndex(searchString); //Row Index - 2
if(searchResult != -1)
{
//searchResult + 2 is row index.
SpreadsheetApp.getActiveSpreadsheet().setActiveRange(ss.getRange(searchResult + 2, 3)).setValue("found here");
}
}
Array.prototype.findIndex = function(search){
if(search == "") return false;
for (var i=0; i<this.length; i++)
if (this[i].toString().indexOf(search) > -1) return i;
return -1;
/* If reference number entered does not exist, show browser pop-up that states "Reference Number
Does not exist. Please enter a valid reference number."
*/
/* Catch any errors and then send them via email to [email protected]
Need error-catching in case the reference number does NOT exist in the
sheet.
*/
}
ありがとうRobin!私は今日必要な修正をしようとします。あなたの答えと説明をありがとうございました。とても有難い! :) – GregB985
ロビン、まず、あなたのご意見に感謝します。私はすでにたくさんのことを学んできました。まだ少し問題があります。私は問題が次のコード行に位置すると信じています。 var searchResult = columnValues.findIndex([searchString]);これは常に-1という値を生成します。結果として、ReferenceNumberのどの値がサブミットされても、セルA1の単語 "Status"が上書きされます。 Logger.Logコードを追加して、何が起きているのか理解しやすくなりました。あなたの助言のために立ってください。ありがとうございました。:) – GregB985
配列でindexOfを実行することはできませんので、私の更新された答えを確認してください。 –