Skip to content

Instantly share code, notes, and snippets.

@papinianus
Last active December 16, 2022 18:25
Show Gist options
  • Save papinianus/6b99394e296cf351d9d217717de436fa to your computer and use it in GitHub Desktop.
Save papinianus/6b99394e296cf351d9d217717de436fa to your computer and use it in GitHub Desktop.
google form create
{
"HeaderInfo": {
"AssemblyVersion": "1.3.26.1",
"BaseSiteId": 7167230,
"Server": "https://demo.pleasanter.org",
"CreatorName": "テナント管理者",
"PackageTime": "2022-12-16T18:24:21.8499706+00:00",
"Convertors": [
{
"SiteId": 7167230,
"SiteTitle": "FormApp",
"ReferenceType": "Results",
"IncludeData": false
}
],
"IncludeSitePermission": false,
"IncludeRecordPermission": false,
"IncludeColumnPermission": false,
"IncludeNotifications": false,
"IncludeReminders": false
},
"Sites": [
{
"TenantId": 13658,
"SiteId": 7167230,
"Title": "FormApp",
"SiteName": "",
"SiteGroupName": "",
"Body": "",
"GridGuide": "",
"EditorGuide": "",
"ReferenceType": "Results",
"ParentId": 7094335,
"InheritPermission": 7094335,
"SiteSettings": {
"Version": 1.017,
"ReferenceType": "Results",
"GridColumns": [
"ResultId",
"Title",
"Locked",
"ClassA",
"ClassB",
"ClassC",
"ClassD"
],
"FilterColumns": [
"Locked",
"ClassA"
],
"EditorColumnHash": {
"General": [
"ResultId",
"Ver",
"Title",
"Body",
"NumA",
"ClassA",
"ClassB",
"ClassC",
"ClassD",
"Locked"
]
},
"Columns": [
{
"ColumnName": "ClassB",
"Anchor": true,
"AnchorFormat": "{Value}"
},
{
"ColumnName": "ClassC",
"Anchor": true,
"AnchorFormat": "{Value}"
},
{
"ColumnName": "ClassD",
"Anchor": true,
"AnchorFormat": "{Value}"
},
{
"ColumnName": "NumA",
"Min": 1.0,
"EditorReadOnly": true
},
{
"ColumnName": "ClassA",
"ValidateRequired": true,
"NoDuplication": true
},
{
"ColumnName": "Locked",
"CheckFilterControlType": 2
}
],
"Processes": [
{
"Id": 1,
"Name": "setBody",
"DisplayName": "サイト読み込み",
"CurrentStatus": -1,
"ChangedStatus": -1,
"OnClick": "main()",
"ActionType": 90,
"View": {
"Id": 0,
"ColumnFilterHash": {
"Locked": "2"
},
"ApiColumnKeyDisplayType": 0,
"ApiColumnValueDisplayType": 0,
"ApiDataType": 0
}
}
],
"Scripts": [
{
"Title": "fillInBody",
"Edit": true,
"Body": "const getSite = (id) =>\n new Promise((resolve, reject) => {\n $p.apiGetSite({\n id: id,\n done: (d) => resolve(d),\n fail: (e) => reject(e),\n });\n });\n\nconst main = async () => {\n try {\n const id = $p.getControl('数値A').val()\n ? $p.getControl('数値A').val()\n : $p.getControl('数値A').text();\n console.log(id);\n const s = (await getSite(id)).Response.Data.SiteSettings;\n const quiz = normalizeItem(s.EditorColumnHash.General, s.Columns);\n $p.set($p.getControl('内容'), JSON.stringify(quiz, null, 2));\n } catch (e) {\n console.log(e);\n }\n};\n\nconst normalizeItem = (items, columns) => {\n return items\n .map((i) => {\n const def = defaultDef(i);\n if (def === undefined) return def;\n const column = columns.filter((e) => e.ColumnName === i)[0];\n if (column === undefined) return def;\n if (column.ValidateRequired !== undefined)\n def.ValidateRequired = column.ValidateRequired;\n if (column.LabelText !== undefined) def.LabelText = column.LabelText;\n if (column.ChoicesText !== undefined)\n def.ChoicesText = column.ChoicesText;\n const types = ['ラジオ', 'チェック', 'プルダウン'];\n const typesDic = {\n ラジオ: 'MultipleChoice',\n チェック: 'Checkbox',\n プルダウン: 'List',\n };\n if (\n def.ChoicesText !== '' &&\n (column.MultipleSelections || types.includes(column.Description))\n ) {\n def.Type = column.MultipleSelections\n ? 'Checkbox'\n : typesDic[column.Description];\n }\n if (def.Type === 'ParagraphText' && column.FieldCss !== undefined) {\n def.Type = 'Text';\n }\n return def;\n })\n .filter((e) => e !== undefined);\n};\nconst defaultDef = (col) => {\n if (col.startsWith('Class')) {\n return {\n Type: 'Text',\n ColumName: col,\n LabelText: col,\n ValidateRequired: false,\n ChoicesText: '',\n };\n }\n if (col.startsWith('Description')) {\n return {\n Type: 'ParagraphText',\n ColumName: col,\n LabelText: col,\n ValidateRequired: false,\n ChoicesText: '',\n };\n }\n if (col.startsWith('Date')) {\n return {\n Type: 'Date',\n ColumName: col,\n LabelText: col,\n ValidateRequired: false,\n ChoicesText: '',\n };\n }\n return undefined;\n};",
"Id": 1
}
],
"ServerScripts": [
{
"Title": "validateSiteId",
"Name": "validateSiteId",
"BeforeCreate": true,
"Body": "try {\n const title = model.ClassA;\n const siteId = siteSettings.SiteId(title);\n if (siteId === 0) {\n context.Error(`no site named ${title}.`);\n } else {\n model.NumA = siteId;\n }\n} catch (e) {\n context.Log(e.message);\n context.Log(e.stack);\n}\n",
"Id": 1
},
{
"Title": "makeGoogleForm",
"Name": "makeGoogleForm",
"BeforeUpdate": true,
"Body": "try {\n const title = model.ClassA;\n const body = JSON.parse(model.Body);\n httpClient.RequestUri =\n 'https://script.google.com/macros/s/____/exec';\n httpClient.Content = JSON.stringify({ Title: title, Body: body });\n [model.ClassB, model.ClassC, model.ClassD] = JSON.parse(httpClient.Post());\n model.Locked = true;\n} catch (e) {\n context.Log(e.message);\n context.Log(e.stack);\n}\n",
"Id": 2
}
],
"UseIncompleteFilter": false,
"UseOwnFilter": false,
"UseNearCompletionTimeFilter": false,
"UseDelayFilter": false,
"UseOverdueFilter": false,
"UseSearchFilter": false,
"NoDisplayIfReadOnly": false
},
"Publish": false,
"DisableCrossSearch": false,
"Comments": []
}
],
"Data": [],
"Permissions": [],
"PermissionIdList": {
"DeptIdList": [],
"GroupIdList": [],
"UserIdList": []
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment