The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
I am working on a custom connector and I have finished almost 75% of my work. My question is related to custom user input.
Here is my navigation pane I want to take input from the user on selecting any table from my navigation and then call YourApiFunction.
Here is my code
section PQExtension1;
Table.ToNavigationTable = (
table as table,
keyColumns as list,
nameColumn as text,
dataColumn as text,
itemKindColumn as text,
itemNameColumn as text,
isLeafColumn as text
) as table =>
let
tableType = Value.Type(table),
newTableType = Type.AddTableKey(tableType, keyColumns, true) meta
[
NavigationTable.NameColumn = nameColumn,
NavigationTable.DataColumn = dataColumn,
NavigationTable.ItemKindColumn = itemKindColumn,
Preview.DelayColumn = itemNameColumn,
NavigationTable.IsLeafColumn = isLeafColumn
],
navigationTable = Value.ReplaceType(table, newTableType)
in
navigationTable;
[DataSource.Kind="PQExtension1", Publish="PQExtension1.Publish"]
//shared PQExtension1.Contents = (authKey as text) =>
shared PQExtension1.Contents = Value.ReplaceType(HelloWorldImpl, HelloWorldType);
HelloWorldImpl = (authKey as text) as table =>
let
url = "https://.../.../spreadsheets",
headers = [ Authorization = "Bearer " & authKey ],
options = [ Headers = headers ],
response = Web.Contents(url, options),
json = Json.Document(response),
items = json[items],
toTable = Table.FromList(items, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
expand = Table.ExpandRecordColumn(toTable, "Column1", {"id", "name", "slug", "folder_id", "created_at"}, {"id", "name", "slug", "folder_id", "created_at"}),
YourApiFunction = (id as text,message as text) as any =>
let
// Parse the JSON response and extract the "items" array
base_url = "https:///.../...//spreadsheets",
url=base_url & "/"&message& "/tables" & "/" & id & "/values/A:ON" ,
headers = [ Authorization = "Bearer " & authKey ],
options = [ Headers = headers ],
response = Web.Contents(url, options),
json = Json.Document(response),
items = json[items],
// Extract the column names from the first array in the "items" array
columnNames = List.First(items),
// Extract the remaining arrays in the "items" array as data
data = List.Skip(items, 1),
// Create a table from the data with the column names
table = Table.FromRows(data, columnNames)
in
table,
convertListToTable = (list as list,message as text) as table =>
let
toTable = Table.FromList(list, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
expand = Table.ExpandRecordColumn(toTable, "Column1", {"id", "name", "slug","created_at","tables"}, {"id", "name", "slug","created_at","tables"}),
ids = expand[id],
apiResponses = List.Transform(ids, (id) => YourApiFunction(id,message)),
combinedTable = Table.Combine(apiResponses)
in
combinedTable,
CreateNavTable = (message as text) as table =>
let
url = url & "/" & message,
response = Web.Contents(url, options),
json = Json.Document(response),
pages = json[pages],
toTable = Table.FromList(pages, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
expand = Table.ExpandRecordColumn(toTable, "Column1", {"id", "name", "slug","created_at","tables"}, {"id", "name", "slug","created_at","tables"}),
addRow = (row) => #table({"Name", "Key", "Data", "ItemKind", "ItemName", "IsLeaf"}, {{row[name],row[id],convertListToTable(row[tables],message), "Item", row[name], true}}),
loop = List.Accumulate(Table.ToRecords(expand), #table({"Name", "Key", "Data", "ItemKind", "ItemName", "IsLeaf"}, {}), (tbl, row) => Table.Combine({tbl, addRow(row)})),
navTable = Table.ToNavigationTable(loop, {"Key"}, "Name", "Data", "ItemKind", "ItemName", "IsLeaf")
in
navTable,
addRow = (row) => #table({"Name", "Key", "Data", "ItemKind", "ItemName", "IsLeaf"}, {{row[name],row[id], CreateNavTable(row[id]), "Folder", row[name], false}}),
loop = List.Accumulate(Table.ToRecords(expand), #table({"Name", "Key", "Data", "ItemKind", "ItemName", "IsLeaf"}, {}), (tbl, row) => Table.Combine({tbl, addRow(row)})),
navigationTable = Table.ToNavigationTable(loop, {"Key"}, "Name", "Data", "ItemKind", "ItemName", "IsLeaf")
in
navigationTable;
// Data Source Kind description
PQExtension1 = [
Authentication = [
Implicit = [Label = "Rows Connector"]
],
Label = "Rows Connector"
];
ok. what is your question?