4

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>
3
  • is it possible that the {!$GlobalConstant.True} is actually implemented as string 'true'?
    – Damecek
    Oct 6, 2021 at 7:55
  • 1
    @Damecek That's actually a really good question. I added a String attribute and the plot thickened further. The {!$GlobalConstant.True} is passed into the string as a boolean! See updated question.
    – Nick Cook
    Oct 6, 2021 at 12:06
  • wow :D, at least you have solution :D
    – Damecek
    Oct 6, 2021 at 14:57

2 Answers 2

2

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.

1

I think I found the underlying issue; I was running into the same thing: using {!$GlobalConstant.True} as an input parameter for a LWC embedded in a flow, resulted in targetConfig property value in the LWC being undefined.

Removing the default="true" property in the LWC's metadata xml (in the targetConfig property) worked, but can't be deployed to orgs that contain flows that consume the LWC without deleting the flows.

Then I found out that if you explicitly set the inputvalue in the flow's metadata file, it works. When I retrieved the flow from a scratch org initially, the flow's xml file didn't have any value for the <inputParameters> that was defaulted for the LWC.

tl;dr:

Add the <inputParameters> tags in the example below to your flow's xml explicitly to set the LWC's targetConfig property value, even (or especially) when the LWC has a default value for that property:

<name>someLWC</name>
<extensionName>c:someLWC</extensionName>
<inputParameters>
    <name>someLWCProperty</name>
    <value>
        <booleanValue>true</booleanValue>
    </value>
</inputParameters>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.