Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Optional parameter of function is making "null" as a parameter

Hey guys, I've built a custom connector and I decided to change the parameter of a function in the Navigator to a dropdown list.
For that, I had to provide function documentation, and since the parameter for the function has to be optional (I don't want it to be passed to Top Level Navigation function), it generated a "null" option:

nullValue in time_range.png

It doesn't cause any errors because it is handled, but I'd like it to disappear. How do I do that without removing "optional"?

Params = type text
meta [Documentation.Description = "Please select a time range",
Documentation.FieldCaption = "Time Range (Default is medium):",
Documentation.AllowedValues = {"Short (4 weeks)","Medium (6 months)","Long (Overall)"}];

 

Function1Type = type function(
optional time_range as Params)
as table;

 

[DataSource.Kind="Project1"]
shared Project1.Function1 = (optional Params) => Value.ReplaceType(Function1, Function1Type);

 

 

1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

Based on my test, it will show a blank rows on my side if no value provided. Sorry for that, but it seems not supported to remove the blank rows from dropdown list.

 

13.jpg

12.jpg

All the code we tested with are  here,the code were modified from the sample customer connector

 

section HelloWorldWithDocs;

[DataSource.Kind="HelloWorldWithDocs", Publish="HelloWorldWithDocs.Publish"]
shared HelloWorldWithDocs.Contents = Value.ReplaceType(HelloWorldImpl, HelloWorldType);

shared Params2 = type text meta [
        Documentation.FieldCaption = "Count",
        Documentation.FieldDescription = "Number of times to repeat the message",
        Documentation.AllowedValues = { "1", "2", "3" }
    ];

HelloWorldType = type function (
    message as (type text meta [
        Documentation.FieldCaption = "Message",
        Documentation.FieldDescription = "Text to display",
        Documentation.SampleValues = {"Hello world", "Hola mundo"}
    ]),
    optional count as (Params2)
    )
    as table meta [
        Documentation.Name = "Hello - Name",
        Documentation.LongDescription = "Hello - Long Description",
        Documentation.Examples = {[
            Description = "Returns a table with 'Hello world' repeated 2 times",
            Code = "HelloWorldWithDocs.Contents(""Hello world"", 2)",
            Result = "#table({""Column1""}, {{""Hello world""}, {""Hello world""}})"
        ],[
            Description = "Another example, new message, new count!",
            Code = "HelloWorldWithDocs.Contents(""Goodbye"", 1)",
            Result = "#table({""Column1""}, {{""Goodbye""}})"
        ]}
    ];

HelloWorldImpl = (message as text, optional count as text) as table =>
    let
        _count = if (count <> null) then count else "5",
        listOfMessages = List.Repeat({message}, Value.FromText(_count) as number),
        table = Table.FromList(listOfMessages, Splitter.SplitByNothing())
    in
        table;

// Data Source Kind description
HelloWorldWithDocs = [
    Authentication = [
        Anonymous = []
    ]//,
    //Label = "Hello World With Docs"
];

// Data Source UI publishing description
HelloWorldWithDocs.Publish = [
    Beta = true,
    Category = "Other",
    ButtonText = { "Hello World With Docs", "Provides an example of how to provide function documentation" }
];


Best regards,

 

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

View solution in original post

4 REPLIES 4
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

Based on my test, it will show a blank rows on my side if no value provided. Sorry for that, but it seems not supported to remove the blank rows from dropdown list.

 

13.jpg

12.jpg

All the code we tested with are  here,the code were modified from the sample customer connector

 

section HelloWorldWithDocs;

[DataSource.Kind="HelloWorldWithDocs", Publish="HelloWorldWithDocs.Publish"]
shared HelloWorldWithDocs.Contents = Value.ReplaceType(HelloWorldImpl, HelloWorldType);

shared Params2 = type text meta [
        Documentation.FieldCaption = "Count",
        Documentation.FieldDescription = "Number of times to repeat the message",
        Documentation.AllowedValues = { "1", "2", "3" }
    ];

HelloWorldType = type function (
    message as (type text meta [
        Documentation.FieldCaption = "Message",
        Documentation.FieldDescription = "Text to display",
        Documentation.SampleValues = {"Hello world", "Hola mundo"}
    ]),
    optional count as (Params2)
    )
    as table meta [
        Documentation.Name = "Hello - Name",
        Documentation.LongDescription = "Hello - Long Description",
        Documentation.Examples = {[
            Description = "Returns a table with 'Hello world' repeated 2 times",
            Code = "HelloWorldWithDocs.Contents(""Hello world"", 2)",
            Result = "#table({""Column1""}, {{""Hello world""}, {""Hello world""}})"
        ],[
            Description = "Another example, new message, new count!",
            Code = "HelloWorldWithDocs.Contents(""Goodbye"", 1)",
            Result = "#table({""Column1""}, {{""Goodbye""}})"
        ]}
    ];

HelloWorldImpl = (message as text, optional count as text) as table =>
    let
        _count = if (count <> null) then count else "5",
        listOfMessages = List.Repeat({message}, Value.FromText(_count) as number),
        table = Table.FromList(listOfMessages, Splitter.SplitByNothing())
    in
        table;

// Data Source Kind description
HelloWorldWithDocs = [
    Authentication = [
        Anonymous = []
    ]//,
    //Label = "Hello World With Docs"
];

// Data Source UI publishing description
HelloWorldWithDocs.Publish = [
    Beta = true,
    Category = "Other",
    ButtonText = { "Hello World With Docs", "Provides an example of how to provide function documentation" }
];


Best regards,

 

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

I see, thank you for the help.
Do you have any clue why you have a blank value but I have a null instead?

Best Regards,
CAOP

Hi @Anonymous ,

 

Could you please try to run the sample code(Hello World with Docs) which is in the document and see what will show? Since Our modified code is very similar as yours, so the problem might be something outside the code.


Best regards,

 

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

I just tried and it works fine.
My project is a little different, as it doesn't prompt the user before the navigation table shows up though.
It's a function that may or may not have one of those params. The default result shows up immediately before any user input.

Screenshot_2.png

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors