Forum Discussion

golbarg's avatar
golbarg
Frequent Visitor
5 years ago
Solved

Issues invoking custom function from another

Hello,

 

I'm having trouble finding what's wrong when invoking a custom function from another.

 

Consider:

 

/* getTimeEntryPage(updateFrom, page) */
(updateFrom as text, page as text) =>
let
    ...
in
    ...

 

 

This works as expected whan manually invoked with, for example: getTimeEntryPage("2021-03-24", "1").

 

Now, I also have this:

 

/* getTimeEntriesFromDate(updateFrom) */
(updateFrom as text) =>
let
    Source = Json.Document(Web.Contents(/*This query works*/)),
    List = {1..Source[total_pages]},
    #"Converted to Table" = Table.FromList(List, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "page"}}),
    #"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "getTimeEntryPage", each getTimeEntryPage(updateFrom, [page])),
    ...
in
    ...

 

 

When I call getTimeEntriesFromDate("2021-03-24") manually, I get the following error:

"Unexpected error: Operation is not valid due to the current state of the object."

 

In the #"Invoked Custom Function" line, the following will work (although will only return a subset of data):

getTimeEntryPage(updateFrom, "1")

 

In the same line, the following will return the same error as above (expected as 1 is a number, not the expected text type):

getTimeEntryPage(updateFrom, 1)

 

Since [page] is set to text type, I don't understand why this is not working. Does anyone have an idea?

 

Note: I've made sure the origin data is clean.

 

Thanks!

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi golbarg 

     

    Are you sure it is the issue with [page]? Can you try to wrap Text.From([page]), see how it goes?

     #"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "getTimeEntryPage", each getTimeEntryPage(updateFrom, Text.From([page])))

     

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi golbarg 

     

    Are you sure it is the issue with [page]? Can you try to wrap Text.From([page]), see how it goes?

     #"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "getTimeEntryPage", each getTimeEntryPage(updateFrom, Text.From([page])))

     

    • golbarg's avatar
      golbarg
      Frequent Visitor

      Hey Anonymous,

       

      Wow, that was easier than expected, it worked, thanks!

       

      Any idea why I need to convert a text value to text? It feels wrong.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi golbarg 

         

        No, it does not seem to be needed to convert a text to text...I tried to replicate your case with a simple custom function and a list of numbers, it worked after the column changed to text, did not occur the issue...maybe you should have a look at your custom function getTimeEntryPage