Lightning Web Components – Fixing LWC Flow Screen Component Error: {$GlobalConstant.True} is Undefined

flow-screen-componentlightning-web-componentsvisual-workflow

Is there a known issue with passing in the {!$GlobalConstant.True} into an LWC FSC?

When I pass {!$GlobalConstant.True} into a Boolean attribute on an LWC, the LWC doesn't receive anything. The variable is undefined.

When I pass {!$GlobalConstant.True} into a String attribute on an LWC, the LWC receives it as a boolean

Am I doing something wrong? Or is this a problem with the flow/lwc interaction.

See below for the setup of the LWC in flow, then the code for the LWC. As you can see, it's a really basic LWC, so can't see how there could be a problem with it.


Flow Screen showing the input variable into my LWC as {!$GlobalConstant.True}
Flow Screen showing the input variable into my LWC as {!$GlobalConstant.True}

Output:

Output when using {!$GlobalConstant.True}

However when I pass in TRUE from a formula, it works as expected

Flow UI showing the formula for input_boolean_formula

Flow Screen showing the input variable into my LWC as input_boolean_formula

Flow Screen showing the input variable into my LWC as input_boolean_formula

Output:

Output when using input_boolean_formula

inputBooleanExample.html

<template>
    inputBoolean: {inputBoolean}<br />
    type: {typeOfBoolean}
    <hr />
    inputString: {inputString}<br />
    type: {typeOfString}
</template>

inputBooleanExample.js

import { LightningElement, api } from 'lwc';

export default class InputBooleanExample extends LightningElement {
    @api inputBoolean;
    @api inputString;

    get typeOfBoolean() {
        return typeof this.inputBoolean;
    }

    get typeOfString() {
        return typeof this.inputString;
    }
}

inputBooleanExample.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>52.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__FlowScreen</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__FlowScreen">
            <property name="inputBoolean" label="Input Boolean" type="Boolean" default="true" role="inputOnly" />
            <property name="inputString" label="Input String" type="String" default="true" role="inputOnly" />
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>

Best Answer

Ok, so there's something funky going on with the Flow engine, and the formula approach is a bit of a red herring.

Short answer, I don't think there's anything wrong with {!$GlobalConstant.True}.

The issue is with the default value.

In my meta.xml, I had default="true" for inputBoolean, so when I added the component to the flow screen, I didn't need to set the value of inputBoolean because it was already set.

If I clear {!$GlobalConstant.True} out of inputBoolean, then add it in again, the component behaves as expected.

This would be why the formula worked; because it wasn't using the default value.

If you come across this issue, just clear the default value out of the input, and add it back again.

I've see this happen with text inputs as well.