Protecting Workflow apps, different settings?

I am making a workflow that emails a report to a customer. It's working great in our test environment (email is coming to me).

Once I protect this app and merge it into our production instance of retool, I need it to send the email to the customer and not to me. And ideally, I don't really need the test instance to trigger at all.

My only thought is to use a javascript if/then clause in the "To" field of the email to send it to diff emails based on detecting the environment. Is there a better way?

Hi @Carol_Scheible,

That seems like a good way to handle it, alternatively you could just make the "to" dynamic with something like this:

{{ workflowContext.environment === 'production' ? 'client@email.com' : 'you@email.com' }}

Thanks, ya, that is what I meant by an if/then clause in the to field. I can do that.

Actually, workflowContext.environment is equal to "production" in our test environment. In the past, I have used window.location and detect what the environment is based on the url of the page. But that isn't possible in the context of a workflow.

I wonder if we have our test environment configured incorrectly (self hosted)?

Is the workflowContext.workflowId the same between your two environments?

I haven't protected any workflow apps, so none exist in our production instance. However, normal retool apps do have the same app id in our test and prod instances.

Well... that's a problem.

Ok, what if you created a helper workflow (or you could use the same one with some routing logic) that can be called via a webhook. The webhook just has to respond with the host from the startTrigger headers.

image

For me, in Retool Cloud, I get "host": "api.retool.com" as a response. Is that value different between your environments?

My instance does not recognize startTrigger
Screenshot 2024-08-23 at 11.14.39 AM

Also trying environment variables, and those are not recognized either.
Screenshot 2024-08-23 at 11.18.04 AM

I'll check with my dev team to see if they have ideas. Perhaps these variables? Environment variables reference | Retool Docs

Actually, my issue may be due to the fact that we have self hosted retool but Temporal hosted Workflows, so perhaps the workflow doesn't have access to all the environments of the self hosted system??

I've never used self-hosted Retool so I'm not familiar with the differences between the two. There are often some weird code editor issues with startTrigger, but it typically does actually exist.

Maybe you need to enable a webhook on your workflow though, otherwise I don't think the startTrigger would be populated with anything. I just called mine via Postman to test, and then I can see the headers from the call which can be used to extract the URL.

You'd probably need to set up a single webhook in prod that gets called from both environments though so you could hardcode the webhook request - you wouldn't want a different endpoint per environment because that's the whole problem you're already trying to avoid.

Hi @Carol_Scheible!

If I understand correctly, you're running a multi-instance deployment so need a way to differentiate between instances from within a workflow - is that right?

The best way to do this is to add a global configuration variable via your org's "Settings -> Configuration variables" menu. I'd recommend ENVIRONMENT but it's really up to you!

image

Once you've done that, you can access that variable as retoolContext.configVars.VARIABLE_NAME form within your workflow.

That should allow you to implement the if/else conditional as suggested above. :+1: Let me know if that doesn't work for you or if you have any follow-up questions!

Thanks for the suggestion. I tried that last Friday and those variables don't seem to be available to workflows :(. Only workflowContext, but that one only has the actual envrionment which is unfortunately "production" in both of our environments. I'm going to see if our devs can change that.

That's odd - you should definitely have access to retoolContext and similar variables inside the JS code block. :thinking: Do you know what version of Retool you're running?

I thought it was odd too. I wondered if it had to do with our Retool instance being self hosted, but the workflow is "Retool-managed Temporal"

Here is from the source code:
'X-Retool-Client-Version': '3.30.2-f7127c2 (Build 3117)',

Ah okay I'm pretty sure this is just a versioning issue, then. A lot of the legacy versions - such as 3.30.2 - never received certain bug fixes and feature rollouts.

I spun up a new instance with the same version and verified that the retoolContext variable is not available. This is fixed in stable version 3.33, though! If you can, I'd strongly recommend upgrading to at least that version.

Configuration variables are by and far away the best way to identify environments in a multi-instance deployment, otherwise I'd suggest another workaround.

Oh wow, thanks!!!

1 Like