6. User inputs
Requirements
- You have done the Wiring inputs and outputs tutorial
What you will learn
- Ask inputs to users before running a Job
- Use these inputs in your Job
What are they used for?
User inputs allows to ask inputs from users when they are trying to run a Job from the application.
In this tutorial
We are going to enrich the previous job with a user input to select which language must be used in the export. The render will be:
And depending of the language selected, these columns will be exported in english or french.
Other examples of use
- Create items from the input reference used by the user
- Select the language that must be used when a catalog is exported
- Select images width and height when images are exported to a zip file
- Mass import items from a file drag and dropped in a file input
Setup
User inputs are defined after the title
property, it's an array:
json
{
"schema": "1.0",
"key": "my_first_job",
"title": "My first job",
"userInputs": [],
"tasks": [],
"outputParameters": {}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
Functionally we will enrich the Job Export excel like this:
User inputs
- Type: SELECT Select language
Tasks
- Export Items Export items from a user selection
- Transform XSLT Transform items for the Generate Excel file
- Generate Excel Generate the Excel file
User outputs
- excel_files Output
files
of the task Generate the Excel file
Update the job like this using the autocomplete:
Best practice
Always use the autocomplete to write user inputs.
Then in the XSLT task, add a param like this:
Best practice
- Always use the autocomplete to select user inputs.
- Use the same
name
as your user input key
You must have:
json
{
"schema": "1.0",
"key": "my_first_job",
"title": "Export excel",
"icon": "file-excel",
"userInputs": [
{
"key": "language",
"title": "Language",
"description": "Select language",
"required": true,
"type": "SELECT",
"options": [
{
"key": "french",
"title": "French"
},
{
"key": "english",
"title": "English"
}
],
"default": "english"
}
],
"tasks": [
{
"name": "table-export-items",
"taskReferenceName": "table_export_items",
"description": "Export items from a user selection",
"optional": false,
"type": "SUB_WORKFLOW",
"inputParameters": {
"tableKey": "PL_DEMO_PRODUCTS",
"mode": "USER_SELECTION",
"fileName": "items.xml"
}
},
{
"name": "file-transformation-xslt",
"taskReferenceName": "file_transformation_xslt",
"description": "Transform items for the Generate Excel file",
"optional": false,
"type": "SUB_WORKFLOW",
"inputParameters": {
"mode": "FILE",
"file": "${table_export_items.output.file}",
"params": [
{
"name": "language",
"select": "${workflow.input.language}"
}
],
"xslt": "file://assets/transform.xslt",
"fileName": "result.xml"
}
},
{
"name": "file-generation-xlsx",
"taskReferenceName": "file_generation_xlsx",
"description": "Generate the Excel file",
"optional": false,
"type": "SUB_WORKFLOW",
"inputParameters": {
"request": "${file_transformation_xslt.output.file}",
"templates": [
{
"key": "template-tutorial",
"file": "file://assets/template-tutorial.xlsx"
}
]
}
}
],
"outputParameters": {
"excel_files": "${file_generation_xlsx.output.files}"
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
The naming convention to access a user input is ${workflow.input.user-input-key}
but always use the autocomplete.
Info
You view that you can pass params to xslt. These params can be user inputs, task outputs or strings. Later view the Jobs examples section for more usages.
Then we need to update the xslt to export french or english depending on the param. In this tutorial we will not dive into xslt and params, for now just update the xslt like this:
xml
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="fn"
xmlns:pl="http://product-live.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="3.0"
exclude-result-prefixes="xs fn pl">
<xsl:output method="xml" indent="yes" encoding="UTF-8" cdata-section-elements="" />
<xsl:param name="language" />
<xsl:template match="/">
<Generate-Excel>
<File>
<File-Name>products.xlsx</File-Name>
<Template-Key>template-tutorial</Template-Key>
<Sheets>
<Sheet>
<Sheet-Name>products</Sheet-Name>
<Cells>
<!-- Update headers depending the language param -->
<xsl:choose>
<xsl:when test="$language='english'">
<Cell-Text line="1" column="3">Title EN</Cell-Text>
<Cell-Text line="1" column="4">Description EN</Cell-Text>
<Cell-Text line="1" column="5">Store price</Cell-Text>
</xsl:when>
<xsl:otherwise>
<Cell-Text line="1" column="3">Title FR</Cell-Text>
<Cell-Text line="1" column="4">Description FR</Cell-Text>
<Cell-Text line="1" column="5">Prix magasin</Cell-Text>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="/Table/Items/Item">
<xsl:variable name="position" select="position()+1" />
<xsl:if test="Field[@key='MAIN_VIEW'] != ''">
<Cell-Image line="{$position}" column="1"><xsl:value-of select="Field[@key='MAIN_VIEW']"/>?width=175&height=175</Cell-Image>
</xsl:if>
<xsl:if test="Identifier[@key='EAN_13'] != ''">
<Cell-Text line="{$position}" column="2"><xsl:value-of select="Identifier[@key='EAN_13']"/></Cell-Text>
</xsl:if>
<!-- Update items depending the language param -->
<xsl:choose>
<xsl:when test="$language='english'">
<xsl:if test="Field[@key='TITLE_EN'] != ''">
<Cell-Text line="{$position}" column="3"><xsl:value-of select="Field[@key='TITLE_EN']"/></Cell-Text>
</xsl:if>
<xsl:if test="Field[@key='DESCRIPTION_EN'] != ''">
<Cell-Text line="{$position}" column="4"><xsl:value-of select="Field[@key='DESCRIPTION_EN']"/></Cell-Text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="Field[@key='TITLE_FR'] != ''">
<Cell-Text line="{$position}" column="3"><xsl:value-of select="Field[@key='TITLE_FR']"/></Cell-Text>
</xsl:if>
<xsl:if test="Field[@key='DESCRIPTION_FR'] != ''">
<Cell-Text line="{$position}" column="4"><xsl:value-of select="Field[@key='DESCRIPTION_FR']"/></Cell-Text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="Field[@key='STORE_PRICE'] != ''">
<Cell-Number line="{$position}" column="5"><xsl:value-of select="Field[@key='STORE_PRICE']"/></Cell-Number>
</xsl:if>
</xsl:for-each>
</Cells>
</Sheet>
</Sheets>
</File>
</Generate-Excel>
</xsl:template>
</xsl:stylesheet>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Then save all your opened files, then delete the old Zip file generated and create a new package with Right Click > Package Job.
The go to https://settings.product-live.com Data Factory > Jobs and update the Job.
Now go to https://app.product-live.com, refresh the page with Ctrl + Shift + R
, select three products and Actions > Export excel. Try to change the language and view that depending the language selected the result in the columns title and description are in english or in french.
Other user inputs
There is three types to user inputs: TEXT
, SELECT
and FILE
.
To learn more about user inputs you can read later the User inputs reference.
What you have learned
- You can ask for user inputs, and then use them as inputs for your Job.
- The order of user inputs displayed is the same as the order in your Job.
Next
You will learn how to use the Decision and Terminate task.