I'm using the Advanced Drive Service to set the Sheets column metadata. The column ID is being set, and I can retrieve it, but the sheetId
property is not getting set.
function setShColumnMetadata() {
var request,response,ss,sh;
ss = SpreadsheetApp.getActiveSpreadsheet();
sh = ss.getSheetByName('Employees');
request = [
{
createDeveloperMetadata:{
developerMetadata:{
metadataKey:"employeeSh_DeptIdCol",
metadataValue:JSON.stringify({
writtenBy:Session.getEffectiveUser().getEmail(),
createdAt:new Date().getTime()
}),
location:{
//See https://developers.google.com/sheets/api/reference/rest/v4/DimensionRange
dimensionRange: {
"sheetId":sh.getSheetId(),
dimension:"COLUMNS",
startIndex:9,//column number + 1 is the real column being watched
endIndex:10
//Even though the end index is one more than the start index its only one column
}
},
visibility:"DOCUMENT"
}
}
}
];
response = Sheets.Spreadsheets.batchUpdate({requests:request}, ss.getId());
Logger.log('response: ' + response)
}
Verification Response:
{
"replies":[
{"createDeveloperMetadata":
{"developerMetadata":
{"metadataKey":"employeeSh_DeptIdCol",
"visibility":"DOCUMENT",
"metadataValue":"{
\"writtenBy\":\"[email protected]\",
\"createdAt\":1530996621771
}",
"metadataId":1988973086,
"location":{
"dimensionRange":{
"startIndex":9,
"endIndex":10,
"dimension":"COLUMNS"
},
"locationType":"COLUMN"
}
}
}
}],
"spreadsheetId":"ID Removed"
}
The problem is in the dimensionRange
This is how it's designated:
dimensionRange: {
//See https://developers.google.com/sheets/api/reference/rest/v4/DimensionRange
"sheetId":sh.getSheetId(),
dimension:"COLUMNS",
startIndex:9, //column number
endIndex:10
//Even though the end index is one more than the
//start index its only one column
}
This is what comes back:
"dimensionRange":{
"startIndex":9,
"endIndex":10,
"dimension":"COLUMNS"
},
There is no sheetId
If I use the following code to get the saved metadata:
function getTheSettingsBack() {
var metaDataClass,ssID,stateFound;
ssID = SpreadsheetApp.getActiveSpreadsheet().getId();
metaDataClass = Sheets.Spreadsheets.DeveloperMetadata;
stateFound = metaDataClass.search({
dataFilters:[{
developerMetadataLookup: {
metadataKey: 'employeeSh_DeptIdCol'
}}]
}, ssID);
Logger.log('stateFound: ' + stateFound)
}
It returns:
{"matchedDeveloperMetadata":
[{"dataFilters":[{"developerMetadataLookup":
{"metadataKey":"employeeSh_DeptIdCol"}}],"developerMetadata":
{"metadataKey":"employeeSh_DeptIdCol","visibility":"DOCUMENT",
"metadataValue":"{\"writtenBy\":\"account name here\",\"createdAt\":1530997558830}",
"metadataId":459573349,
"location":{
"dimensionRange":{"startIndex":9,"endIndex":10,"dimension":"COLUMNS"},
"locationType":"COLUMN"}}}]}
Still no sheetId
I don't know if I'm doing something wrong, or if there is something wrong with the Advanced Sheets Service.
The Sheets Advanced API is ON, and turned on in my cloud console, and the version is version 4.
setShColumnMetadata()
,sheetId
is included in the response. And also I confirmed that aftersetShColumnMetadata()
was run, the values retrieved usinggetTheSettingsBack()
havesheetId
. So how about trying this for a new Spreadsheet? I thought that when a new Spreadsheet is created, the issue might be removed. If this was not useful for your situation, I'm sorry. – TanaikesheetId
missing from the object information. But, I just found out, that I don't really need that information. It is immaterial to me at this point. I set the MetaData for a column to watch, moved the column, and thestartIndex
andendIndex
settings changed in the MetaData. That's what I really need. So, even though I'd like to know why this is happening in my paid account, I might not really care if I can keep track of the columns being moved. – Alan Wellsresponse = Sheets.Spreadsheets.batchUpdate({requests:request}, ss.getId(), {fields:"replies/createDeveloperMetadata/developerMetadata/location/dimensionRange/sheetId"});
? In my environment, only sheetId can be retrieved whensetShColumnMetadata()
including it is run. If this was still the same results, I'm sorry. – Tanaikegid=0
,sheetId
is not included indimensionRange
. When your script is used to the sheet withgid=#########
which is except for the number of0
,sheetId
is included indimensionRange
. I thought that this might be an internal issue of GAS side, because when the value is0
, the property is not added. Is this useful for resolving your issue? If your issue had already been resolved, I'm sorry. – Tanaike