Variables of type JSON in AEM Workflow

Starting with AEM Forms 6.5, we can now create variables of type JSON in AEM Workflow. Typically you will create variables of type JSON if you are submitting Adaptive Forms based on JSON schema to an AEM Workflow or you want to store the results of a Form Data Model Invoke operation. The following video walks you through the steps required to create and use a variable of type JSON in AEM workflow

If using AEM Forms 6.5.0

When you are creating a variable of type JSON to capture the submitted data in your workflow model, please do not associate the JSON schema with the variable. This is because when you submit JSON schema based Adaptive Form the submitted data is not compliant with the JSON schema. The JSON schema complaint data is enclosed in afData.afBoundData.data element.

Transcript
In this video, we’re gonna take a look at using variables of type JSON and variable of type string. So, what you see on my screen is a work flow model open in the edit mode. So to break up the variable stack, I click on this stack here and you can see that there are two variables created. To create a variable, you simply click on this add variable, provide a appropriate name, and select the appropriate label type. In this case, I’ve already created two variables one of JSON, another one of string type.
The first step that you need to do is to initialize these variables in your work flow. So, to initialize the variable, I have used a set variable component, which is out of the box in AEM form 6.5. I open up its configuration properties, add to mapping tab, and you can see here that I mapped these two variables here. So let’s go and take a look at this submitted data variable that was mapped by using the Relative to Payload option and we’ll specify the value call data for JSON. What that means is, there will be a file ‘call data.json’ stored in payload related to the workflow. And this is the same name that we have provided when we configured an active form submission options. The next is the submit an email variable levels mapped. So though, this variable was mapped using the JSON Dot Notation and it was mapped to a JSON Type Variable called submitted data, and we have used the DOT notation to expat into the appropriate element of your JSON data. So in this case the email element is under the data element, which is under AF bound data element, which is under the AF data element. So this is how you would use a JSON DOT notation to map to a variable of type string. So once your variables have mapped, the next thing that we need to do is to use them in an assigned task or in an send email operation. So, this is my assign task operation here, I open up the forms and documents, notice its type adaptive form, and use adaptive form with submitted to the workflow option, then I’m repopulating the adaptive form using the variable of time submitted data, and the rest of the tabs are self-explanatory. I’m using the assigned to be the admin user, the actions are as default, and as one step I like to press default settings. The next is the send email. So this is the send email component, which comes with AEM forms. In this, I specify the email details here, I’m using the SJ email template, the sender details is hardcoded, the recipient details is populated using the variable here. So this is a variable, and this is the submit an email variable that was populated from the data that was submitted into the workflow. So this is how you would use a JSON type data and of a string type variable in a AEM workflow.

If using AEM Forms 6.5.1 and above

You can map the schema with the variable of type JSON in your workflow model. You can then use the schema browser to map the schema elements with your string/number variables in your workflow model

Transcript
In this video we will take a look at associating schema with variables of type JSON. So I have this workflow model, which has two variables, one is of type string, another one is of type JSON. So here, for my variable of type JSON, I’ve associated a schema by selecting the Schema Browser, or the selection dialog, and selecting the appropriate schema which is residing in your content repository . So once you have associated a schema with your variable, life becomes much easy for you to initialize other variables. So, for example, if I want to initialize the SubmitterEmail variable, I click into my Set Variable operation here.
I’ve already initialized the SubmittedData by mapping it to a Data.json file which will be available relative to the payload, and then I click on Add Mapping here, and I’m going to map my SubmitterEmail variable here. The mapping mode is going to be JSON Dot Notation. I have to select the JSON type variable, which is SubmittedData. And since our SubmittedData, the JSON type variable is backed by a schema, I I can simply open this up to open the schema structure here, and select the appropriate element that I want to map to my SubmitterEmail. So this is how you can use a schema and map the element in that schema to a particular variable using the new capability introduced in AEM Forms 6.5.1.

To get the assets working on your system, please follow the following steps:

recommendation-more-help
8de24117-1378-413c-a581-01e660b7163e