Returning data from a dialog

What’s the pattern if we need to return data from a Dialog?
I see that you can set a property in the dialog to ‘output’, and then it seems like it’s an event emitter…and the web talks about subscribing to get the output.
Might there be an example of this available?

In Apex Designer, dialog inputs and outputs are the same as regular component inputs and outputs. Please describe what you want to do and I can suggest a pattern.

sure, it’s a file upload, then create business object dialog, and want to return the id of the created business object.
So i have a property in the dialog to hold the value that I want to return, but not sure the right way to do that…as an output parameter and some subscribe thing?

If you have an output named idCreated of type number, and you want to send that output to the component above, you would do this:

this.idCreated.emit(newBusinessObject.id);

“emit” is the way that you “send” an output to the caller.

The component above would have something like this in the template:

idCreated triggers handleNewId($event)

$event contains the value that is emitted inside the component.

For reference, if you have a property named “exchangedValue” that is an input and an output, after you make an update, you need to emit it with a slightly different name:

this.exchangedValue = 47;
this.exchangedValueChange.emit(this.exchangedValue);

The caller and either listen to the “exchangedValueChange” event like the previous example or the caller can use two way binding to their own property named myCopy:

exchangedValue is linked to myCopy

That is equivalent to this:

exchangedValue is evaluated from myCopy
exchangedValueChange triggers myCopy = $event

putting the ‘idCreated triggers…’ as a property on the Dialog template entry causes an error, it wants it to be an input…am I defining this in the wrong place? Or does it indeed have to be an input and output?

and the ‘emit’ command gives an error
Property ‘emit’ does not exist on type ‘string’.
even if you define the field as a formControl…
Property ‘emit’ does not exist on type ‘ApexFormControl’.

to summarize the solution that I used:

In the Dialog:

  • A property set to output (number in my case)
  • Button click triggers .click()
  • Input has uploadImage() method
  • uploadImage has needed code to get the file, etc then creates the Image business object directly, then emits that id of the Image
const newImage = await Image.create(data);
		debug('newImage', newImage);
		this.chosenFieIdId.emit(newImage.id);

On the calling Page

  • The Dialog definition has a property for the above ‘chosenFieldId’ as the property name, with triggers and a method passing ($event).
  • the method has a parameter (number in my case) and it processes the id (in my case, storing it in the currently being edited business object.