Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

On premises Data Gateway Data Source for optional parameters

Hi,

I am trying to use On - premises Data Gateway with my Custom connector, I added Test Connection section in my code:

DemoProject= [TestConnection = (dataSourcePath) =>
let
json = Json.Document(dataSourcePath),
parameter1 = json[parameter1],
parameter2 = json[parameter2],
parameter3 = json[parameter3]
in
{ "DemoProject.Contents", parameter1, parameter2, parameter3},
Authentication = [
UsernamePassword = [
UsernameLabel = "Username",
PasswordLabel = "Password",
Label = "DemoProjectCredentials"
]
],
Label = "DemoProject API"
];

My DemoProject.Contents looks like : 

[DataSource.Kind="DemoProject", Publish="DemoProject.Publish"]
shared DemoProject.Contents = Value.ReplaceType(DemoProjectImpl, DemoProjectType);

DemoProjectType = type function (
parameter1 as (type text meta [
DataSource.Path = false,
Documentation.FieldDescription = "Defines parameter1"
]),
parameter2 as (type text meta [
Documentation.FieldDescription = "Defines parameter2"
]),
optional parameter3 as (type text meta [
Documentation.FieldDescription = "Defines parameter3."
]))
as table meta [
Documentation.Name = "DemoProject"
];

DemoProjectImpl = (parameter1 as text, parameter2 as text, optional parameter3 as text) =>
let
NavigationTables = DemoProjectNavTableQueryFolding(parameter1, parameter2, parameter3)
in
NavigationTables;

When I remove word optional for last parameter and remove DataSource.Path = false, I get 

And also in in Gateway logs there is:

GatewayPipelineErrorCode=DM_GWPipeline_UnknownError
GatewayVersion=
InnerType=ValueException
InnerMessage=<pi>[Expression.Error] The field 'parameter1' of the record wasn't found.</pi>
InnerToString=<pi>Microsoft.Mashup.Engine1.Runtime.ValueException: [Expression.Error] The field 'parameter1' of the record wasn't found.
at Microsoft.Mashup.Engine1.Runtime.RecordValue.IndexOf(String field)
at Microsoft.Mashup.Engine1.Runtime.RecordValue.get_Item(String field)......

 

Any ideas why it happens? artemus

 

  • I haven't done this too much, but I think if you remove DataSource.Path, you must instead add to your DemoProject record:

    MakeResourcePath = (parameter1) => parameter1,
    ParseResourcePath = (resource) => { resource },

     

    Assuming that parameter1 is the sole determiner of the login context. If you also need other parameters, you can add them to the parameter list, and use something like parameter1 & "/" & parameter2 for the return value. ParseResourcePath does the reverse of what MathResourcePath does, in that if using parameter1 and paramter2, you could have: {Text.BeforeDelimiter(resource, "/"), Text.AfterDelimiter(resource,"/")}

  • Anonymous's avatar
    Anonymous
    5 years ago

    artemus Thanks a lot for suggestion, it works

    Type = "Singleton",
    MakeResourcePath = () => "MyConnector",
    ParseResourcePath = (resource) => { },
    TestConnection = (resource) => {"() => true"},

3 Replies

  • artemus's avatar
    artemus
    Microsoft Employee

    I haven't done this too much, but I think if you remove DataSource.Path, you must instead add to your DemoProject record:

    MakeResourcePath = (parameter1) => parameter1,
    ParseResourcePath = (resource) => { resource },

     

    Assuming that parameter1 is the sole determiner of the login context. If you also need other parameters, you can add them to the parameter list, and use something like parameter1 & "/" & parameter2 for the return value. ParseResourcePath does the reverse of what MathResourcePath does, in that if using parameter1 and paramter2, you could have: {Text.BeforeDelimiter(resource, "/"), Text.AfterDelimiter(resource,"/")}

    • Anonymous's avatar
      Anonymous
      Not applicable

      artemus  With DataSource.Path=false we can exclude parameter from datasource path, if I remove it and will add MakeResourcePath = (parameter1) => parameter1,
      ParseResourcePath = (resource) => { resource }...does that rule will remain, does parameter will be excluded?

      • Anonymous's avatar
        Anonymous
        Not applicable

        artemus Thanks a lot for suggestion, it works

        Type = "Singleton",
        MakeResourcePath = () => "MyConnector",
        ParseResourcePath = (resource) => { },
        TestConnection = (resource) => {"() => true"},