Project Role Allocations (Google Apps Script for Sheets)
Create project role allocation pivot table based on projects names, users and their roles.
Use
The names of tables at the far end of this code. Even if you don't ready anything else, please read through the examples below. The script can be used as a continuation of the sheet generated by the script gas-sheets-merge.
Dependencies
This script requires the Sheets API. Failure to enable the API / list it as a resource in the script editor causes the error Reference error: Sheets is not defined
). To enable the API and use it, refer to stackoverflow.
This API has a default quota of 100 reads/day. After that it throws a meaningless error message such as Internal Error Encountered
on the line with Sheets.Spreadsheets.get()
.
Example 1
In the first example, we start with a sheet containing the project names, users and their roles. We filter out the items we're interested in, and generate a Pivot Table showing the project role allocations.
Input
Starting with the projects names, users and their roles in sheet persons. Note that multiple projects may be assigned to a single username
.
Username | Preferred Name | Person Type | Role | Project Allocation 1 | Project Allocation 2 |
---|---|---|---|---|---|
jvonk | Johan | Employee | Student | School | Java |
svonk | Sander | Employee | Student | Reading | School |
brlevins | Barrie | Employee | Adult | BoBo | |
tiger | Tiger | Cat | Pet | Purr | |
owen | Owen | Cat | Pet | Purr | Sleep |
Filter
Filter out the people using Data > Create a Filter > filter
to filter on Person Type == Employee
Username | Preferred Name | Person Type | Role | Project Allocation 1 | Project Allocation 2 |
---|---|---|---|---|---|
jvonk | Johan | Employee | Student | School | Java |
svonk | Sander | Employee | Student | Reading | School |
brlevins | Barrie | Employee | Adult | BoBo |
Run the script
Create a script such as onopen.gs
that contains an opOpen()
function to add an
item to the Google Scripts menu bar. Remember to fill in your srcColumnLabels
and
sheet names.
function onOpen_prjRoleAlloc() {
onPrjRoleAlloc({srcColumnLabels: ["Project Allocation*", "Username", "Role" ],
srcSheetName: "persons",
pvtSheetName: "role-alloc"});
function onOpen() {
SpreadsheetApp.getUi()
.createMenu("YourName")
.addItem("Merge with go-persons example1", 'onOpen_prjRoleAlloc').addToUi();
}
The srcColumnLabels
uses a wildchard in Projects*
to indicate that all
columns starting with Projects
should be considered.
Running onProjectRoleAlloc()
generates a sheet called role-alloc-raw and
the pivot table role-alloc.
The script will not include the lines that are hidden by the filter.
Intermetiate output
Underwater, the script creates a sheet that forms the raw input for the Pivot Table (role-alloc-raw). If the sheet already exist, it will reuse it.
Project Allocation | Username | Role | Ratio |
---|---|---|---|
School | jvonk | Student | 0.5 |
Java | jvonk | Student | 0.5 |
Reading | svonk | Student | 0.5 |
School | svonk | Student | 0.5 |
BoBo | brlevins | Adult | 0.5 |
Output
The script creates a project role allocation Pivot Table (role-alloc). If the sheet already exist, it will preserve the formatting and only update its datarange.
Project Allocation | Username | Student | Adult |
---|---|---|---|
School | jvonk | 0.5 | |
svonk | 0.5 | ||
Java | jvonk | 0.5 | |
Reading | svonk | 0.5 | |
BoBo | brlevins | 1.0 |
Example 2
In this example we show that projects can be grouped together into themes.
Input
Starting with the same filtered input from the first example in sheet persons
Username | Preferred Name | Person Type | Role | Project Allocation 1 | Project Allocation 2 |
---|---|---|---|---|---|
jvonk | Johan | Employee | Student | School | Java |
svonk | Sander | Employee | Student | Reading | School |
brlevins | Barrie | Employee | Adult | BoBo |
Themes
The projects are grouped into themes using the sheet themes
Project Allocation | Theme |
---|---|
School | Study |
Java | Study |
Chef | Chores |
Reading | Relax |
BoBo | Work |
Run the script
This time, we pass an extra parameter to OnPivot.main()
that specifies the themes sheet name.
Change the onopen.gs
script from example 1, to include the name of the Themes Sheet.
function onOpen_prjRoleAlloc() {
onPrjRoleAlloc({srcColumnLabels: ["Project Allocation*", "Username", "Role" ],
srcSheetName: "persons",
pvtSheetName: "role-alloc",
theSheetName: "themes"});
function onOpen() {
SpreadsheetApp.getUi()
.createMenu("YourName")
.addItem("Merge with go-persons example1", 'onOpen_prjRoleAlloc').addToUi();
}
Intermetiate output
The sheet that forms the raw input for the Pivot Table (role-alloc-raw), now starts with
the column Theme
.
Theme | Project Allocation | Username | Role | Ratio |
---|---|---|---|---|
Study | School | jvonk | Student | 0.5 |
Study | Java | jvonk | Student | 0.5 |
Relax | Reading | svonk | Student | 0.5 |
Study | School | svonk | Student | 0.5 |
Work | BoBo | brlevins | Adult | 0.5 |
Output
The script creates a project role allocation Pivot Table (role-alloc)
Theme | Project Allocation | Username | Student | Adult |
---|---|---|---|---|
Study | School | jvonk | 0.5 | |
svonk | 0.5 | |||
Java | jvonk | 0.5 | ||
Relax | Reading | svonk | 0.5 | |
Work | BoBo | brlevins | 1.0 |
Example 3
This example extends the previous example by allowing allocation percentages in the input
Input
Starting with the same filtered input from the first example in sheet persons
Username | Preferred Name | Person Type | Role | Project Allocation 1 | Project Allocation 1 % | Project Allocation 2 |
---|---|---|---|---|---|---|
jvonk | Johan | Employee | Student | School | 80% | Java |
svonk | Sander | Employee | Student | Reading | School | |
brlevins | Barrie | Employee | Adult | BoBo |