41
Completed

Run sub-tasks

1) Allow the "perform task" action to have unlimited number of parameters

2) Allow the "perform task" action to return an array variable

6 replies

Any chance for the JavaScrip tasker performTask function to now have a pass through option. In a scriptlet to pass through the variables in the task in which it is embedded, and in a WebView to pass through the variables of the scene.

Ok, added! Can you please try this version? https://drive.google.com/file/d/1clW433pxvypJQM0QhuKyIk0pmTC7Hccx/view?usp=sharing

Does not seem to work. Have I got the right version 5.9.4 beta 6? There is no check box for use passthrough on the javascriptlet either dialog either.

Also, did you know that accessing an array element from javascript only works if the array base is not set. If it is, then array[1] just returns the second character of the base.

There's no checkbox :) You just need to pass the extra parameters in the function... How did you try to use it exactly?

Isn't that what beta testing is all about?

A

Indeed it is, I just feel the need to mess around sometimes and keep things lively.

Turns out this wasn't that hard after all :D

I've added 3 new options:

  • In the Perform Task action I've added the Local Variable Passthrough option which will make all local variables available to the other task
  • In the Return action I've added the same option but also a new Replace On Passthrough which allows you to control to send all variables back to the calling task but optionally only send variables that do not already exist

Makes sense? :)

If you can give this version a go and see what you think... https://drive.google.com/file/d/1UfMEt1H6wjlMDdsqByn-flCRqE45PdJ1/view?usp=sharing

TP

This is great! Will give this a testing this weekend. One addition to consider - rather than just having all variables pass-through, also have an option to send only specific variables.

Because for example let's say that "Perform Task" is being called in the middle of a "For" loop. Whatever variable is constantly changing with each iteration of the loop may or may not be wanted in the called Task.

So you could have two options like:

PASS ALL VARIABLES (checkbox)

PASS ONLY THE FOLLOWING VARIABLES: %name,%age,%date,%location

A

Yes, I agree with Tasker Pro, a variable list text input field should be present with a toggle to enable or disable pass through. If the field is empty, pass all. Otherwise if the field is set to a comma separated list, pass only those. It should be same for both Perform Task and Return action.

Passing all will just create a mess with commonly used variables, like %num in for loops, %return, etc.

This will be especially useful when a number of buttons in a scene need the same task that needs access to the scene's variables.

TP

Definitely will be useful in a scene Steve!

I ran a bunch of tests using a Scene, some where variables are set in the Task that creates the Scene, and others where variables are created in the Scene itself, and when using "Perform Task" from a Scene button - the variables in both cases get sent just fine so that part works!

Edit: I had previously thought that the variable name(s) and value(s) returned to the Scene by a "Return" action weren't getting stored in the Scene. Something must have been off in that test because in testing it again - all is well it seems!

TP

Gotta fix the "Return" action though - it's still wanting a varname put in the "Value" field even when "Local Variable Passthrough" is checked.

A

Why though? The value field should still be settable even if pass through is enabled since that will be set to the Perform Task return variable in the calling task. That convention should not be broken. Local variables should be sent back separately. We just need an  optional variable list input field for both actions.

TP

Oh it should definitely be settable. It's just at the moment it is demanding the field be filled in or you can't add the action. 

A

Oh, you are right. But maybe local pass through should be added to the Stop action for that, let's create more work for joão ;)

Ok, I'll add a field to optionally only send a few variables and also make the return variable not mandatory.  Thanks for the feedback everyone!

A

Welcome and thanks for the field :)

Ok, made those changes in this version. https://drive.google.com/file/d/1UfMEt1H6wjlMDdsqByn-flCRqE45PdJ1/view?usp=sharing

Can you please check if it's working correctly? :)

A

The optional variable list and "Local Variable Passthrough" is working, but "Replace On Passthrough" is not working. The values of the caller task variables are overridden even with it disabled, with or without the optional variable list. Moreover, IMO the "Replace On Passthrough" should ideally work even if the optional variables list is passed. I have uploaded a project at the following link to test it all.

https://taskernet.com/shares/?user=AS35m8mXdvaT1Vj8TwkSaCaoMUv220IIGtHe3pG4MymrCUhpgzrat6njEOnDVVulhAIHLi6BPUt1&id=Project%3ALocal+Variable+Passthrough

A

Moreover, the "Return" actions also fails with "Error: null" if the "Local Variable Passthrough" is not enabled. Can't check %errmsg since no "Continue Task After Error".

TP

Tested and can confirm the few errors/bugs you encountered there 

A

So one of my normal task was failing. It appears that even the "Stop" toggle of the "Return" action is not working. Moreover, the "Return" action failure when "Local Variable Passthrough" is disabled only occurs if u directly run the task, if u run the task from another task, the error doesn't occur and %err and %errmsg do not get set either. I could check those because "Stop" toggle is not working. :p

It's a whole mess. So joão when you say "check if it's working correctly?", I think my answer will have to be "kinda no, but depends on what you are trying to do...." :p

I have updated the taskernet project to test the new findings.

Since "Stop" toggle is not working, better disable your profiles since it could be dangerous, or revert to an older working version.

A

And thanks for confirming @Tasker Pro

Thank you very much for the debugging :) My bad for not testing all possible use cases. Sorry about that.

I think I fixed all of those now! Can you please try this version? https://drive.google.com/file/d/1UfMEt1H6wjlMDdsqByn-flCRqE45PdJ1/view?usp=sharing

A

Thanks for the fixes and bugs are always welcome :).  Replace On Passthrough is working fine now and the Return action is not failing anymore but Stop toggle of Return action is still not stopping the task and the task continues on. Maybe use the taskernet project for testing, it will be simpler :)

Oops, sorry about that!  Hopefully this now fixes that last issue! Can you please let me know if it does?

https://drive.google.com/file/d/1clW433pxvypJQM0QhuKyIk0pmTC7Hccx/view?usp=sharing

A

You have done it! Congratulations! Release the beast on reddit for mass testing! :p

TP

Woohooo! 😁👍👍

Nice :D Thanks for testing!

A

You are very welcome :)

AG

The current workaround for not being able to return arrays is to use variable join and split.

Instead of unlimited parameters, an idea would be to have all local variables in the calling task be available in in the called task and returned to the calling task. In addition, variables created in the calledctask should be returned  alto the calling task. If done well, this could permit sharing local variables between an unlimited number of levels of tasks.

Should be part of Tasker.

TP

I think this is an interesting idea, because this is exactly the way Scenes currently work.

Whenever a Task calls for a Scene to open, all of the Task's local variables and arrays are available within the Scene.

And the Scene holds on to them as long as the Scene exists.

I think a good solution to apply this to "Perform Task" would be to make sending all the variables from the calling Task an option. So there would be a checkbox in the "Perform Task" action labelled "Share Variables" :)

In which case all local vars get sent into the sub-Task, and when the sub-Task is finished any modified var values (as well as any new var names and values created) can get sent back to the calling Task, via a modified "Return" action.

The "Return" action would have its own checkbox option for "Return All Variables". This way, with the checkbox options - all current Tasks using the current method will still function, and anyone who wants to use "Perform Task" in the usual way can still do so.

TP

There is currently a workaround way to send umlimited varnames and var values to the other Task using a single AutoTools action:

https://www.reddit.com/r/tasker/comments/3d1f0q/how_to_send_unlimited_par_tasker_variables_over/ct2ckv8/

Yes, that is a work around, but it can require a significant number of actions to accomplish.