PhixFlow Help
14. Workflows - context variables
In this chapter we will create a simple workflow, to create invoices for a chosen contact. This uses many of the features of app building you have used up to this point, and adds a new feature - context variables - which are crucial as you take users from one screen to another in a workflow.
Intermediate step: assign transaction to contact
In this exercise, we will create the intermediate step of the workflow, where the user can assign a transaction to a chosen contact. In the exercise you will need a sample file of transactions. You can download the file here:
Create this first step of the workflow in your app. To recap the steps in the video:
- Add a file collector to your model, call this
Invoice Transactions
- Upload the test file Invoice Transactions.xlsx to configure the file collector and create a stream
- Load the list of invoice transactions
- Create a new dashboard
Assign Transactions
- Add two views to the dashboard:
- In the top half, create a form called
Contact Details Assign Trans
- Open the configuration form for the stream
Contacts
, and drag on all attributes on to the form - Hide the
UID
field, and re-arrange the fields on the form - don't forget about the layout options on forms under [right click] → Arrange the selected items - Create a grid view in the bottom half, from the stream
Invoice Transactions
, including all attributes from the stream
- In the top half, create a form called
- Create an action on the
Contacts
stream - we will use this to initiate the invoice creation process from theContacts
dashboard:- Name:
Start invoice creation
- Display Name:
Start invoice creation
- In the section Action Completion:
- (We will not tick Close Parent Dashboard - in this case, the parent dashboard is the
Contacts
dashboard, and we want to leave this open) - Tick Open Post Dashboard, then Apply
- Drag in the dashboard
Assign Transactions
to create a dashboard rule
- (We will not tick Close Parent Dashboard - in this case, the parent dashboard is the
- Open the section Context Parameters
- Create a new context parameter:
- Name:
UID
- Expression:
_form.UID
- This will take the value of UID from the currently select contact in the
Contacts
app, and save it to a context variable; we can then use this value at the next stage of the process
- Name:
- Name:
- Add a button to the
Contacts
dashboard to start the invoice process - Call the button:
Create Invoice
- Associate the custom action
Start invoice creation
with the button - Update the button label to
Create Invoice
- Apply a filter to the contact form in the dashboard
Assign Transactions
to show the selected contact:- Right click on the contact form in the dashboard, and go to Dashboard Options → Show Element Details
- In the element details, add a background filter:
- Name:
by UID
- Condition:
UID
=_context.UID
(don't forget to make the condition an expression, by pressing the ABC button)
- Name:
Open the Contacts
dashboard, and go into App Mode. Select a contact, and press the Create Invoice
button - this will take you to the Assign Transactions
dashboard, with details for the selected contact shown.
Final step: create invoice
Complete configuration of the invoice generation process in your app. To recap the steps in the video:
- Create a stream
Invoices
, by creating a stream from the hover menu on the streamContacts
- Set the period of the stream to Transactional
- Drag all attributes from
Contacts
intoInvoices
- Drag all attributes from
Invoice Transactions
intoInvoices
- Create a dashboard
Invoices
to show invoices: add a grid view including all attributes from the streamInvoices
, and hide theUID
field - Create a custom action that will take users from the intermediate stage of the process to the invoices screen (the intermediate dashboard is backed by the stream
Invoice Transactions
):- Open the configuration form for the stream
Invoice Transactions
, and add an action:- Name:
Complete invoice creation
- Display Name:
Complete invoice creation
- In the Action Completion section:
- Tick Close Parent Dashboard; in this case the parent dashboard will the be intermediate dashboard, used to assign transactions to a contact, so we want to close this when the user goes to complete the process
- Tick Open Post Dashboard, and drag in the dashboard
Invoices
to create a dashboard rule
- Open the section Context Parameters:
- Tick Include Previous Context Parameters - this will bring forward any context parameters from the previous dashboard, in this case
UID
- Add new context parameters, to capture new details from the intermediate dashboard - these are details of the chosen transaction
- First, get the dashboard element name of the grid view of transactions from the intermediate dashboard (
Assign Transactions
) - Use this to set the expression for each context parameter as: [dashboard element name of transactions in
Assign Transactions
].[View attribute name] - Do this for:
SKU
TransValue
TransDate
- First, get the dashboard element name of the grid view of transactions from the intermediate dashboard (
- Tick Include Previous Context Parameters - this will bring forward any context parameters from the previous dashboard, in this case
- Name:
- Open the configuration form for the stream
- Add a button to the intermediate dashboard (
Assign Transactions
) to complete the generation of an invoice:- Call the button
Complete invoice creation
- Find the custom action under the stream
Invoice Transactions
, and drag it on to the button to set the custom action - Update the button label to
Complete Invoice Creation
- Call the button
- Complete configuration of the stream
Invoices
, in the model view:- Make the stream
Contacts
static; this will stop this stream being run when the streamInvoices
is run - Open details for the pipe that connects
Contacts
andInvoices
- Set Data To Read = All; after you added importing of contacts from files into the contacts app, there are multiple runs in the
Contacts
stream, and this setting ensures that we can get all contacts down the pipe - Create a filter on the pipe:
UID
=_context.UID
(don't forget to press ABC)
- Set Data To Read = All; after you added importing of contacts from files into the contacts app, there are multiple runs in the
- Open the configuration form for the stream
Invoices
, and set the expressions forSKU
,TransDate
andTransValue
, in each case using the expression:_context.
[context parameter name]
- Make the stream
- Create a task plan,
Complete invoice creation
, to run theInvoices
stream - Complete configuration of the custom action
Complete invoice creation
:- Tick Run Selected Task Plan, and drag in the task plan
Complete invoice creation
to create a task plan rule
- Tick Run Selected Task Plan, and drag in the task plan
In summary, our custom action to complete invoice creation now:
- Brings forward the
UID
context variable from the previous dashboard (because we have set Include Previous Context Parameters) - Sets three new context variables to capture details of the chosen transaction from the intermediate dashboard
- Starts a task plan to update the stream
Invoices
with an analysis run - Closes the parent dashboard (
Assign Transactions
) - Opens the
Invoices
dashboard
- Add a filter to the
Invoices
dashboard to show only invoices for the currently selected user:- From the grid view in the
Invoices
dashboard, open the dashboard element details - Add a background filter:
UID
=_context.UID
(don't forget to press the ABC button)
- From the grid view in the
Open the Contacts
app, and go into App Mode. Press Create Invoice
. In the intermediate step, select a transaction, then press Complete Invoice Creation
. You should see details for a new invoice, for the contact you chose on the Contacts
dashboard, and the transaction you chose on the Assign Transactions
dashboard.
An alternative method of implementing the final step of the workflow would be, instead of running analysis to update the Invoices
stream, create an Insert action on the Invoices
stream. From the intermediate step, you would need to pass up all details needed to populate an invoice record - including any contact fields required. Then you would associate this action with the button on the intermediate dashboard that completes the invoice creation process.
Which method you choose is a design decision based on the the data set you are dealing with, and the process you are trying to implement. If, for example, the final step of creating invoices involves a lot of rules which are easily implemented in analysis - such as enriching the data through lookups, then the method we have used here would be best.
However, if the creation of invoices involved no additional logic, using an insert action is probably easier to implement. If you have time, try and create invoices using this alternative method.
Please let us know if we could improve this page feedback@phixflow.com