Nie działa usuwanie za pomocą skryptu (Script deletion does not work)

Nie działa usuwanie wierszy arkusza za pomocą skryptu.

Oto skrypt. Właściel ja , kto ma dostęp - każdy

function doGet(e)
{
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");
var sheet = ss.getSheetByName("Sheet1");
return addUser(e,sheet);
}

function doPost(e)
{
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");
var sheet = ss.getSheetByName("Sheet1");
return addUser(e,sheet);
}
function usun_w(e,sheet)
{
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");
var sheet = ss.getSheetByName("Sheet1");
var record = e.parameter.id ;
sheet.deleteRow(parseInt(record) + 1);
return ContentService.createTextOutput("Success");
}
W tej samej aplikacji ,dodawanie wiersza przez skryp działa.
Odczyt z arkusza działa poprawnie. Z listview wybierany jest numer rekordu (wiersza) do usunięcia.
Bloki kodu są następujące:

Bardzo proszę o pomoc co robię żle.

You have not changed the call function addUser to usun_w

image

Also, you can have both the add and delete functions in the same script, by sending a variable, e.g

fn = add  >> e.parameter.fn or fn = delete >> e.parameter.fn

Here you can see a full Create Read Update and Delete solution

1 Like

Zmieniłem skrypt do usuwania na

function doGet(e)

{ 

  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");

  var sheet = ss.getSheetByName("Sheet1"); 

  return addUser(e,sheet);  

}

function doPost(e) 

{ 

  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");

  var sheet = ss.getSheetByName("Sheet1"); 

  return addUser(e,sheet);  

}

function addUser(e,sheet)

{

    var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");

    var sheet = ss.getSheetByName("Sheet1");

    var record = e.parameter.id ;

    sheet.deleteRow(parseInt(record) + 1);

    return ContentService.createTextOutput("Success");  

}

Nie jestem pewien czy dobrze zmieniłem
ale dalej nie działa .

Narazie chcę mieć dodawanie wiersza i usuwanie wiersza w dwóch osobnych skryptach.

Oczywiścieblok dla przycisku

usuń

Zmieniłem skrypt na

function doGet(e)

{ 

  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");

  var sheet = ss.getSheetByName("Sheet1"); 

  return usun_w(e,sheet);  

}

function doPost(e) 

{ 

  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");

  var sheet = ss.getSheetByName("Sheet1"); 
  return usun_w(e,sheet);  

}

function usun_w(e,sheet)

{

    var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");

    var sheet = ss.getSheetByName("Sheet1");
    var record = e.parameter.id ;
    sheet.deleteRow(parseInt(record) + 1);
    return ContentService.createTextOutput("Success");  

}

ale still does not work, Please help TIMAI2

Have you deployed your changed script to a new version?

TAK.
Czy ten skrypt poniżej jest poprawny

function doGet(e) { 
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");
var sheet = ss.getSheetByName("Sheet1"); 
return usun_w(e,sheet);  
}

function doPost(e) { 
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");
var sheet = ss.getSheetByName("Sheet1"); 
return usun_w(e,sheet);  
}

function usun_w(e,sheet) {
var record = e.parameter.id ;
sheet.deleteRow(parseInt(record) + 1);
return ContentService.createTextOutput("Success");  
}

Co ciekawe skrypt który dodaje wiersze do tego samego arkusza działa poprawnie

function doGet(e) { 
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");
var sheet = ss.getSheetByName("Sheet1");
return addUser(e,sheet);  
}

function doPost(e)  { 
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1spR8Tt6Ojj0uIMRwmO1nDSrOxWCodgBqtILy8p5YpwU/edit#gid=0");
var sheet = ss.getSheetByName("Sheet1"); 
return addUser(e,sheet);  
}

function addUser(e,sheet) {
var id = e.parameter.id; 
var opis = e.parameter.opis; 
var obrazek =e.parameter.obrazek;
var glos = e.parameter.glos; 
var film =e.parameter.film;
sheet.appendRow([id,opis,obrazek,glos,film]);
}

Your delete script looks OK.

Nr wiersza wybrany z listview wygląda też na poprawny, ale nadal nie działa.
Oczywiście po każdej zmianie skrypu i nowym wdrożeniu zmieniam link w aplikacji w bloku button delete.

w tym bloku

Of course, after each script change and new implementation, I change the link in the application in the button delete block.

You shouldn't have to...

I did what I was told but still does not work. I have no slighest idea what is wrong. I even make a new script with the content which seems to be good( You have checked it) and deploy it from the very beging. I have received the information that the new script was deployed and can be dangerous. I put the new link in my application but situation does not change.

This script is working for me

function doGet(e) { 
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/<YOUR URL HERE>/edit#gid=0");
var sheet = ss.getSheetByName("Sheet1"); 
var record = e.parameter.id ;
sheet.deleteRow(parseInt(record) + 1);
return ContentService.createTextOutput("record deleted");  
}

Other than that I do not know what else to suggest. You appear to have worked things up from the beginning.

Confirm that the script is set to run as your google account, and that Anyone has access?
Confirm your sheet is called Sheet1
Confirm you have the spreadsheet url correct?
Confirm you have given permission for the script to run against your account?
Confirm you have deployed your script after making changes?

Now works !!!. The problem was not in the script but in application.
For the test if the script works I placed in the script var record = 2 ( just for the test , without id parameter) , after this test I was sure that the script works.

I thought that is no difference if we put the details of the spreadsheet in script or in tha application ( i.e Id of the spreadsheet and the name of the sheet).
Thank TIMI2 you very much for your patiencea and cooperation!

thumbsup2

Please to hear you finally sorted it out ....

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