cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
oguruma
Helper II
Helper II

Functions inside Connector parameters?

I'd like to use a function to define parameters inside a Custom Connector API call. 

 

Is it possible to break out of the {} tags and insert a function instead of typing literals? For example

 

 

MyAPI.GetRecords("Accounts",{Filters:"I need my function to replace this string"}).data

 

5 REPLIES 5

 

Usually you could use

 

 

With({myFunction:someFunction},MyAPI.GetRecords("Accounts",{Filters:myFunction}).data)

 

 

If it doesn't let you, then you can't do that and have to use literals.

 

However, you could also try this:

 

 

MyAPI.GetRecords("Accounts",{Filters:"I need my" & function & "to replace this string"}).data

 

 

or this:

 

 

MyAPI.GetRecords("Accounts",{Filters:$"I need my {function} to replace this string"}).data

 

 

 

Does any of above help @oguruma ? 

I guess the problem really is more of setting variables I can use in the parameters..

 

Part of the problem is that the actual API accepts a multi-dimensional array, however, for some reason, the Connector will only work if I pass a String. So, I have to simulate the array with a String (the String just happens to contain the multi-dimensional array). 

 

I have to find some kind of way to store something like ''"company_name"",""="",""Microsoft"" as a variable, then inject that/those variables into the middle of 

 

MyAPI.GetRecords("Accounts",{Filters:"[[""Status"",""="",""active""], & [""another string here
""] & ,"[""maybe one more strong""]]"}).data

...plus find some kind of way to add the commas in the Filters string to separate the arrays. 

 

//pseudocode - untested
//an example below
With

(

    {
        myStatusParam:"Status"
       ,myStatusValue:"active"
       ,myCompanyParam:"Company"
       ,myCompanyValue:"Microsoft"
    }
   ,MyAPI.GetRecords("Accounts",{Filters:$"{myStatusParam}={myStatusValue}&{myCompanyParam}=myCompanyValue"}).data

)

 

 

If you don't like the $ sign syntax, then 

 

 

 

//pseudocode - untested
//an example below
With

(

    {
        myStatusParam:"Status"
       ,myStatusValue:"active"
       ,myCompanyParam:"Company"
       ,myCompanyValue:"Microsoft"
    }
   ,MyAPI.GetRecords("Accounts",{Filters:myStatusParam & "=" & myStatusValue & "&" & myCompanyParam & "=" & myCompanyValue).data

)

 

 

or if you need to keep it exactly in the format you gave, and assuming that it was correct, then like this:

 

//pseudocode - untested
With
(
   {sp:"Status",e:"=",sv:"active",ash:"another string here",moms:"maybe one more string"}
   ,MyAPI.GetRecords("Accounts",{Filters:$"[[""{sp}"",""{e}"",""{sv}""],[""{ash}""],[""{moms}""]]"}).data

)

 

 Try it with the dollar sign syntax, like above, since it's quite a bit more complicated without it:

 

 

 Without dollar sign syntax, it might be like this below, far more complicated than with the dollar sign syntax, and I am less sure it's correct:

 

//pseudocode - untested
With
(
   {sp:"Status",e:"=",sv:"active",ash:"another string here",moms:"maybe one more string"}
   ,MyAPI.GetRecords("Accounts",{Filters:"[[""" & sp & """,""" & e & """,""" & sv & """],[""" & ash & """],[""" & moms & """]]"""}).data

)
​

 

See if it helps as starting point @oguruma 

 

 

How do I break out of the "" to insert functions/variables inside of a string?

For example I have a literal string of 

MyAPI.Getrecords({filters:"[[""parent"",""="",""LEAD-ID-1234""]]"}).message

but I'd like to replace ""Lead-ID-1234"" with the variable varSelectedLead.

I gave the information already in my previous responses, but I'll now give another example only for the formula you gave and a simpler example this time:

 

For

 

 

//untested and assuming your formula works as given
MyAPI.Getrecords({filters:"[[""parent"",""="",""LEAD-ID-1234""]]"}).message

 

you can try

 

//untested pseudo formula, may require modification
MyAPI.Getrecords({filters:$"[[""parent"",""="",""{varParentValue}""]).message

 

 or

 

//untested pseudo formula, may require modification
MyAPI.Getrecords({filters:"[[""parent"",""="",""" & varParentValue & """"]).message

 

Does it work?

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,312)