cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jhirshland Frequent Visitor
Frequent Visitor

Unable to create dynamic function parameters in Power BI Custom Connector

I am trying to get the dropdown to be populated by another function and am getting a Microsoft.Mashup.Engine.Interface.UnpermittedResourceAccessException (I believe means forbidden access) or a grayed out dropdown.

 

It seems like there was already someone trying to do this (https://github.com/microsoft/DataConnectors/issues/70 and Use-an-API-Call-to-Populate-Custom-Data-Connector-Settings/), but no one appears to have solved this issue. The main problem I believe is that you are trying to call a function from within a type definition. It doesn't seem to work for me, so does anyone have any ideas?

 

Here is my complete test source code. The API is public so anyone can try running this.

 

// This file contains your Data Connector logic
section IssueTest;

DefaultRequestHeaders = [
    #"Accept" = "application/json"
];

[DataSource.Kind="IssueTest", Publish="IssueTest.Publish"]
shared nothing = () =>
    let 
        a = "Hello From Issue Post"
    in
        a;

[DataSource.Kind="IssueTest"]
shared IssueTest.Contents = Value.ReplaceType(IssueImpl, IssueType);

IssueType = type function (
    optional employee as (type text meta [
        Documentation.FieldCaption = "Pick Employee",
        Documentation.AllowedValues = getEmployees // also tried * = employees which gives (Microsoft.Mashup.Engine.Interface.UnpermittedResourceAccessException)
    ]))
    as text meta [
        Documentation.Name = "IssueTest"
    ];


IssueImpl = (optional employee as text) =>
    let
        a = getEmployees()
    in
        a;


[DataSource.Kind="IssueTest"]
getEmployees = () =>
    let
        Source = Web.Contents("https://gorest.co.in/public-api/users/"),
        Parsed = Json.Document(Source),
        Result = Parsed[result],
        Table = Table.FromValue(Result),
        Column = Table.RemoveColumns(Table,{"Value"}),
        List = Table.ToList(Column),
        Buffer = List.Buffer(List)
        // Check = Buffer{0} is text // Check if the list is filled with text values
    in
        Buffer;

// This gives a mashup exception (Microsoft.Mashup.Engine.Interface.UnpermittedResourceAccessException)
// [DataSource.Kind="IssueTest"]
// shared empl = employees;

employees = 
    let
        Source = Web.Contents("https://gorest.co.in/public-api/users/"),
        Parsed = Json.Document(Source),
        Result = Parsed[result],
        Table = Table.FromValue(Result),
        Column = Table.RemoveColumns(Table,{"Value"}),
        List = Table.ToList(Column),
        Buffer = List.Buffer(List)
        // Check = Buffer{0} is text // Check if the list is filled with text values
    in
        Buffer;


// Data Source Kind description
IssueTest = [
    Authentication = [
        // UsernamePassword = [], // will end up needing to use Basic Auth
        Implicit = []
    ],
    Label = Extension.LoadString("DataSourceLabel")
];

// Data Source UI publishing description
IssueTest.Publish = [
    ...
];

IssueTest.Icons = [
    ...
];

 

 

2 REPLIES 2
Community Support Team
Community Support Team

Re: Unable to create dynamic function parameters in Power BI Custom Connector

Hi @jhirshland 

Could you tell what's your aim?

It's hard to find it from your code.

 

In addition, you can find how to create dynamic function parameters in Power BI from these links:

Creating Dynamic Parameters in Power Query

Dynamic API parameters in Power BI

Custom Functions Made Easy in Power BI Desktop

 

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Highlighted
jhirshland Frequent Visitor
Frequent Visitor

Re: Unable to create dynamic function parameters in Power BI Custom Connector

Sorry. There also might be some confusion of the word parameter, I mean it as a function parameter when making a query in a custom data connector. I am unable to populate the Documentation.AllowedValues with values returned by an API call. Here is a screenshot:

 

Screenshot (4).png

 

Does that make sense @v-juanli-msft ? Thank you for responding quickly.

Helpful resources

Announcements
Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Power BI Helps Homeless and Trouble Youth

Power BI Helps Homeless and Trouble Youth

We spoke with Power BI Super User, Greg Deckler, about his charity work

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 27 members 859 guests
Please welcome our newest community members: