尝试通过将工作表变量(单元值)传递给函数,然后传递给stringfy来发出POST请求,从而将表单数据与JSON数据一起传递
https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
请原谅我的新颖之处,并提出Google大学毕业生有史以来最糟糕的问题。我已经搜寻了很多东西,但似乎无法将我的头围住stringify概念,尤其是如何使用JSON数据创建POST请求。
当我设置objectid的值(通过传递单元格函数数据)时,它导致请求成功 例如:
var OBJECTID=84098;
但是由于字符串化,从CELL FUNCTION引用OBJECTID失败
function POSTUPDATES (Token, OBJECTID, STATUS, AVGDRYDENSITY, AVGMOISTURE, GUAGENUMBER, PROCTOR, OPTIMUMMOISTURE, T99ORT180, LIFTTHICKNESS, LIFTNUMBER, REMARKS)
///TEST LOADED VARIABLES
{
///setting variables here (bypassing cell function variables) results in a successful request
var AVGDRYDENSITY = 114.8;
var PROCTOR = 119.9;
var LIFTNUMBER = 1;
var LIFTTHICKNESS = 12;
var AVGMOISTURE = 2;
var STATUS = 'Closed';
var OPTIMUMMOISTURE = 7.2;
var GUAGENUMBER = 7848;
var REMARKS = 'updated with sheet';
///setting OBJECTID (no quotes) results in a successful request. HOWEVER WITHOUT quotes fails due to stringify.data
var OBJECTID = 84098;
var Token = "secret";
// Make a POST request with a JSON payload.
var data = {
"attributes": {
"Remarks": REMARKS,
"Lift_Number": LIFTNUMBER,
"Lift_Thickness_in": LIFTTHICKNESS,
"Local_Proctor_Value": PROCTOR,
"Local_Optimum_Moisture": OPTIMUMMOISTURE,
"Average_Dry_Density": AVGDRYDENSITY,
////objectid set here
"OBJECTID": OBJECTID,
"Average_Field_Moisture": AVGMOISTURE,
"Status": STATUS,
"GuageNumber": GUAGENUMBER
}
}
var formData = {
'f': 'json',
'method' : 'post',
'Token': Token,
'updates' : "[" + JSON.stringify(data) + "]"
};
var options = {
'method' : 'post',
'payload' : formData
};
var request = UrlFetchApp.getRequest('https://maps.horrocks.com/arcgis/rest/services/DensityModule/FeatureServer/0/applyEdits/', options)
var response = UrlFetchApp.fetch('https://maps.horrocks.com/arcgis/rest/services/DensityModule/FeatureServer/0/applyEdits/', options);
////摘要
var OBJECTID=84098; ///SUCCESSFUL REQUEST
var OBJECTID = OBJECTID; ///(FROM CELL FUNCTION) FAILS