Skip to content

Commit

Permalink
adding users, tables, and fields
Browse files Browse the repository at this point in the history
adding Metadata folder
adding Users function
adding Tables function
adding Fields function
  • Loading branch information
craibuc committed Mar 11, 2021
1 parent a02f276 commit 23268a3
Showing 1 changed file with 92 additions and 2 deletions.
94 changes: 92 additions & 2 deletions BambooHrPQExtension/BambooHrPQExtension.pq
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,50 @@ shared BambooHrPQExtension.Contents = (optional subdomain as text) =>
source
;

/*
Purpose:
Return tables and other objects that will be visible in Power BI's Navigation dialog
Parameters:
subdomain - the name of the customer's subdomain (e.g. https://[subdomain].bamboohr.com/)
*/
shared NavigationTable = (subdomain as text) =>
let
objects = #table(
{"Name","Key","Data","ItemKind", "ItemName","IsLeaf"},
{
{"EmployeeDirectory","employeeDirectory",EmployeeDirectory(subdomain), "Table","Table",true}
{"EmployeeDirectory","employeeDirectory",EmployeeDirectory(subdomain), "Table", "Table", true},
{"Users","users",Users(subdomain), "Table", "Table", true},
{"Metadata", "metadata", MetadataTable(subdomain), "Folder", "Folder", false}
}),
NavTable = Table.ToNavigationTable(objects, {"Key"}, "Name", "Data", "ItemKind", "ItemName", "IsLeaf")
in
NavTable;
NavTable
;

/*
Purpose:
Return "metadata" nodes
Parameters:
subdomain - the name of the customer's subdomain (e.g. https://[subdomain].bamboohr.com/)
*/
MetadataTable = (subdomain as text) as table =>
let
objects = #table(
{"Name","Key","Data","ItemKind", "ItemName","IsLeaf"},
{
{"Tables", "tables", Tables(subdomain), "Table", "Table", true},
{"Fields", "fields", Fields(subdomain), "Table", "Table", true}
}),
NavTable = Table.ToNavigationTable(objects, {"Key"}, "Name", "Data", "ItemKind", "ItemName", "IsLeaf")
in
NavTable
;

/*
Purpose:
Retrieve table of active employees
Parameters:
subdomain - the name of the customer's subdomain (e.g. https://[subdomain].bamboohr.com/)
Links:
https://documentation.bamboohr.com/reference#get-employees-directory-1
*/
Expand All @@ -41,6 +71,66 @@ EmployeeDirectory = (subdomain as text) =>
#"Reordered Columns"
;

/*
Purpose:
Retrieve table of active employees
Parameters:
subdomain - the name of the customer's subdomain (e.g. https://[subdomain].bamboohr.com/)
Links:
https://documentation.bamboohr.com/reference#get-a-list-of-users-1
*/
Users = (subdomain as text) =>
let
Source = GetResource( subdomain, "/meta/users" ),
#"Converted to Table" = Record.ToTable(Source),
#"Expanded Value" = Table.ExpandRecordColumn(#"Converted to Table", "Value", {"id", "employeeId", "firstName", "lastName", "email", "status", "lastLogin"}, {"id", "employeeId", "firstName", "lastName", "email", "status", "lastLogin"}),
#"Removed Other Columns" = Table.SelectColumns(#"Expanded Value",{"id", "employeeId", "firstName", "lastName", "email", "status", "lastLogin"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Other Columns",{{"id", Int64.Type}, {"employeeId", Int64.Type}, {"lastLogin", type datetimezone}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"lastLogin", "lastLoginUtc"}}),
#"Added Custom" = Table.AddColumn(#"Renamed Columns", "lastLoginLocal", each DateTimeZone.ToLocal([lastLoginUtc])),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"lastLoginLocal", type datetimezone}})
in
#"Changed Type1"
;

/*
Purpose:
Retrieve the tables
Parameters:
subdomain - the name of the customer's subdomain (e.g. https://[subdomain].bamboohr.com/)
Links:
https://documentation.bamboohr.com/reference#metadata-get-a-list-of-tabular-fields-1
*/
Tables = (subdomain as text) =>
let
Source = GetResource( subdomain, "/meta/tables" ),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"alias", "fields"}, {"alias", "fields"}),
#"Expanded fields" = Table.ExpandListColumn(#"Expanded Column1", "fields"),
#"Expanded fields1" = Table.ExpandRecordColumn(#"Expanded fields", "fields", {"id", "name", "alias", "type"}, {"id", "name", "alias.1", "type"}),
#"Renamed Columns" = Table.RenameColumns(#"Expanded fields1",{{"alias", "tableName"}, {"name", "columnDescription"}, {"alias.1", "columnName"}, {"type", "columnDataType"}, {"id", "columnId"}})
in
#"Renamed Columns"
;

/*
Purpose:
Retrieve the fields
Parameters:
subdomain - the name of the customer's subdomain (e.g. https://[subdomain].bamboohr.com/)
Links:
https://documentation.bamboohr.com/reference#metadata-get-a-list-of-fields
*/
Fields = (subdomain as text) =>
let
Source = GetResource( subdomain, "/meta/fields" ),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "name", "type"}, {"id", "name", "type"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Column1",{{"id", type number}})
in
#"Changed Type"
;

/*
Purpose:
Retrieve the JSON document from the specified resource
Expand Down

0 comments on commit 23268a3

Please sign in to comment.