Redirect if a single query is empty

Can anyone helo me with a on load redirect ??

I have try to redirect if a single query server connect is empty. I have tried using a flow with autorun but cant get this work. Any recommendation.

<script is="dmx-flow" id="redirect" type="text/dmx-flow" autorun="true">{
  condition: {
    outputType: "boolean",
    if: "{{hotelInfo.data.hotelInfo.!hasKey('idHotel')}}",
    then: {
      steps: {
        run: {
          name: "reditect",
          outputType: "text",
          action: "{{browsercontrol.goto('/')}}"
        }
      }
    }
  }
}</script>

Length option is not available for a single query.

You can’t use the length formatter for single query as it doesn’t return an array.

Use

{{!hotelInfo.data.hotelInfo.idHotel}}

This will evaluate to true if the query returns no result.

I have used like that but seems that even if the query has results or not redirect.

The conditions seems to not affect at all. Always evaluate as TRUE.

Well maybe your expression is just wrong. Double check it and/or test it on your page to see what it returns. Also check browser console for errors.

I try to debug making the idHotel display on Alert but seems that Flow is not getting the values from the server connect action. Does the order from server connect and flow with autorun affect? Do I need to submit like a param?? Alert do not diplaying nothing.

<script is="dmx-flow" id="redirect" type="text/dmx-flow" autorun="true">[
  {
    alert: {
      outputType: "boolean",
      message: "{{hotelInfo.data.hotelInfo.idHotel}}"
    }
  }
]</script>

and get this error on console.

You need to run the flow after the server connect runs, i.e call it on success of the server action, not on page load.

I have also test that and no results. Somehow seems that the Flow is not getting the the data.

Captura de Pantalla 2024-04-17 a la(s) 14.26.08 Captura de Pantalla 2024-04-17 a la(s) 14.25.54

Test if your expression is correct then. Make sure to use the data picker in the flow to select it and don’t write it by hand.
Also try binding this expression on the page in a paragraph for example, to test it.

The expression is correct

<h1 class="tittle-md-nb">Descripción Value = {{hotelInfo.data.hotelInfo.idHotel}}</h1>

If I run the Flow like this

<script is="dmx-flow" id="redirect" type="text/dmx-flow">[
  {
    alert: {
      outputType: "boolean",
      message: "Test message"
    }
  }
]</script>

With a fixed text work perfect:

If I use any expression like this:

<script is="dmx-flow" id="redirect" type="text/dmx-flow">{
  alert: {outputType: "boolean", message: "{{hotelInfo.data.hotelInfo.idHotel}}"}
}</script>

Get this error.

Captura de Pantalla 2024-04-17 a la(s) 14.33.22

I think this is a bug. Any help @Teodor?? Somehow the flow dont get the values from server connect. I am running the flow on server connect success.

What about {{!hotelInfo.data.hotelInfo}}?

1 Like

This seems to work. Thanks @franse :grinning:

<script is="dmx-flow" id="Redirect" type="text/dmx-flow">{
  condition: {
    outputType: "boolean",
    if: "{{!hotelInfo.data.hotelInfo}}",
    then: {
      steps: {
        run: {
          name: "redirect-page",
          outputType: "text",
          action: "{{browsercontrol.goto('/')}}"
        }
      }
    }
  }
}</script>
1 Like