function doPost(e){
Logger.log(JSON.stringify(e));
const pr = JSON.stringify(e);
var a1 = pr.parameters.aoutlet;
AddRecord(a1);
}
// pr
//{"parameters":{"Bill-Amt":[""],"Vendor0":["ko"],"aoutlet":["GM"],"Vendor":["555"].....
And it Apps Script says... Cannot read property 'aoutlet' of undefined (line 13, file "Code")
CodePudding user response:
In your situation, how about the following modification?
From:
function doPost(e){
Logger.log(JSON.stringify(e));
const pr = JSON.stringify(e);
var a1 = pr.parameters.aoutlet;
AddRecord(a1);
}
To:
function doPost(e){
Logger.log(JSON.stringify(e));
var a1 = e.parameters[0].aoutlet;
AddRecord(a1);
return ContentService.createTextOutput("ok");
}
or
function doPost(e){
Logger.log(JSON.stringify(e));
var a1 = e.parameter.aoutlet;
AddRecord(a1);
return ContentService.createTextOutput("ok");
}
Note:
- When you modified the Google Apps Script, please modify the deployment as a new version. By this, the modified script is reflected in Web Apps. Please be careful this.
- You can see the detail of this in the report of "Redeploying Web Apps without Changing URL of Web Apps for new IDE".
CodePudding user response:
Issue:
You're using JSON.stringify() on the e
object, so pr
is a string.
You are then trying to access properties in that string as if it was an object, and this is causing your error.
Solution:
Don't use JSON.stringify
. Use e
instead:
var a1 = e.parameters.aoutlet;