In a Flow Screen LWC, I would like to allow the admin to build a series of screens with input fields mapped to sObject fields of their choosing, and automatically set the input value to the corresponding field on an sObject variable of their choosing.
Building a component to render the appropriate input for an Object/Field is pretty straightforward, but I'm struggling with getting the value assigned to the sObject variable. Is this something that is even possible?
When you pass an sObject variable into a Flow Screen LWC, it looks like it is just an object with the assigned field names/values as properties. For example:
I have a Flow record variable for My_Object__c called "myObject" and My_Object__c.Field__c is assigned a value of 'test', then "myObject" is passed into a property called "record" in the LWC. In the LWC:
console.log(JSON.stringify(this.record)); // {"Field__c" : "test"}
A little bare-bones I thought, but something we can work with. If I copy this object to another property and add another field with a value, then notify the Flow of the change, it seems like it might work:
this._record = JSON.parse(JSON.stringify(this.record));
this._record['Field2__c'] = 'another value';
console.log(JSON.stringify(this._record)); // {"Field__c" : "test","Field2__c" : "another value"}
this.dispatchEvent(new FlowAttributeChangeEvent('record', this._record));
That piece will execute without error, but then later in the Flow if you try to reference the newly assigned field, the Flow fails with the error "The flow failed to access the value for myObject.Field2__c because it hasn't been set or assigned."