App & Workflow Sync Function Signatures

I believe I have uncovered what has been driving me crazy while trying to use Sync Functions

TL;DR

Sync functions in apps take one argument, an object with named parameters. Sync functions in Workflows take however many arguments you define. This is confusing and I believe Workflows should be changed to match the behavior in Apps.

Longer Version

In APPS, we can define sync functions with named parameters, and these are now the required properties on an object to pass to the function. The function accepts one parameter even if you define two with the UI.

Here is the exported ToolScript

In Workflows, we can define sync functions with named parameters, and these are now the required positional parameters to pass to the function. The function accepts the ordered parameters as you defined with the UI.

And here is the export of the workflow I accidentally saved over my test :frowning:

I like the parameters as a named object personally since you already surface them in the hints when using the sync function.
image

What do you think @Erin_Masatsugu?

1 Like

@khill-fbmc unfortunately, this is correct!

A bit of context on why this is the case:

  • Functions were first supported for Workflows, using positional parameters, as I understand it to prioritize the ease of calling functions with only 1-2 parameters.
  • As we designed how functions should work in Apps, we (perhaps similarly to you) thought named parameters would scale better with the # of arguments.

As you've noticed, we surface the expected parameters in the method signature, which we hope will give users a hint as to how to call the function, but I think there are a few other things we can try (linting, etc).

It is certainly a less than ideal scenario for functions in Apps + Workflows to work differently in this regard, and we are planning to make these experiences more consistent before bringing this feature to GA.

Thanks for bringing this up as I know this has been a source of confusion for others.

3 Likes

I still seem to be experiencing issues trying to call my sync function.

This screenshot has a lot going on, but you can see from my tests, I can't get the sync function to work in a map.

Edit: I exported the wrong thing, I'll have to re-upload later.

1 Like

Here's my rubber duck debugging...

So sync functions return an object, with my value as data
image

Ok, so if I access .data I should get KEVIN_H right?
image

Wait, I thought we were getting an object, lets try a variable.
image
Ok, yeah, I see it right there, .data

Let's access that.
image
What? where is my value??

Can we get .data from another code block?


Hmm... yes... I see another object with .data but its wrapped again?

Am I supposed to .data.data??
image

How do I get my sync function to work in a loop?

I think you may be running into another difference bw App functions + Workflow functions, which is that Workflow functions are async and need to be awaited. This is also something we are looking to consolidate before releasing this feature more broadly.

1 Like

Oh man... I was carrying the concept of "Sync Functions" over into workflows!

image
I see from this little tooltip now await is needed.

Maybe instead of a tooltip, have that info more prominent? or call the whole tab Async Functions?

Even though this is frustrating, I am happy to surface this information for everyone else who might be as confused as me.

3 Likes