Autorun flow by condition

Hello can someone help me understand app connect flow.

I have custom url scheme for when my cordova app is opened appname:// I save this to a Wappler variable to use within the app.

function handleOpenURL(url) { 
setTimeout(function () { 
dmx.parse("openURL.setValue('" + url + "')") 
}, 0) }

I want to check this variable if it has particular state returned for security, if the state is correct I then want to run a flow to send this to the server.

I haven’t worked out how to search for this state parameter yet but for now I have is not empty, my question is does this condition when met at anytime run the flow? or is there something else i’m missing. If I auto run will this only run once or every time the condition is met. I would expect there to be a condition input to be below the auto run checkbox.

Sorry if this has been asked before, I couldn’t find the answer.

I guess another question would be can I call the flow from javascript using some if statment to verify the state?

1 Like

Hi,

You cannot put a condition on the “auto-run” param by UI. Same goes for “auto-load” for server connects.
But, you can try to dmx-bind these properties. I have used on server connects, so here is an example of that:

dmx-bind:noload="varSomething.value == 'xyz' ? '' : 'noload'"

The noload param needs ‘noload’ value to stop server connect from loading automatically. Anything else, and it will not auto-load. Using the ternary operator in code view, setting value becomes dynamic.
Although, this does not always work. I am not sure why, but I have seen this fail for me at some places.

As for JS, you can use that too.
Just use dmx.parse() method to run access and run Wappler’s DMX stuff.
dmx.parse(' varSome.value == "xyz" ? myFlow.run() : "" ')

2 Likes

The answer from sid with the dmx-bind will not work, it should return a boolean and it is only used on the initial load on dom ready.

Running a flow from javascript can be done with dmx.parse like sid mentioned.

if (myState == true) {
  dmx.parse('flow1.run()');
}
1 Like

Thank you

Maybe that's why I see inconsistent performance on this. Thanks for the info. :slight_smile:

I use it in SPA content pages. I have cases where content page's server connect uses some variable from main page. So, once this content page has loaded in the memory, then, even if I am on some other content page, changing the value of the index page variable loads the server connect of earlier content page - even though its not visible (but was loaded - so "in memory").

In such case, this dmx-bind on noload works well.

1 Like

Hi, I figured out how to extract the state parameter now, i’m wondering how I can pass this value into the flow?

function handleOpenURL(url) {
    setTimeout(function () {
        dmx.parse("openURL.setValue('" + url + "')")
        var queryString = url
        var url = new URL(queryString);
        var urlState = url.searchParams.get("state");
        if (urlState == 'xxxxxxxxxxxxxxxxxxxx') {
            dmx.parse('flowCodeExchange.run()');
        }
    }, 0)
}

Just configure this on the page using Wappler’s action picker somewhere… Eg on a button click… There you will be able to see the syntax of passing params to flow.

Or i can share that later when I log in to my system.

1 Like

ok thanks but I’m running the code from javascript,
I think I don’t need a flow anymore, I’m trying to use server connect directly post to pass the code and state. Still I’m unsure of how to do that, could you show me please?

dmx.parse(“sc1.load({param1:‘value1’, param2:‘value3’})”) ;

Something like this. But this works only for GET params.
If you want to do POST, you will have to either create a Wappler form with hidden fields, set them in JS and do a ‘form1.submit()’ from JS.
Or, use AJAX.

1 Like

I see thanks, is not possible to use api action for this? I’m creating another post to illustrate my need more clearly.

API action is Wappler solution. What I have suggested is JS based.

So this will not work?

dmx.parse("apiCodeExchange.load({code:'" + urlCode + "'})");

Well, it’s running the action fine but I don’t get how to pass the code value,

image

image

I should be using get global instead. solved.

1 Like

That's right. GET & POST params are available from there.

1 Like