Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

You will need two import files for the exercises. You can download these files here:

Running task plans, refresh actions

Widget Connector
width900
urlhttps://www.youtube.com/watch?v=LpPq2utF12s&index=14&list=PLbPt6SI1Zhb_n3lXboTC_Qzq0Kg2x8LtT
height500

Set up a button to run a task plan in your app to import contacts from files. To recap the steps in the video:

Load up contact file

  • Create file importer called Import Contacts
  • Load up the test file Contact Import 1.xlsx to configure the file importer, and create a stream

Link imported contacts into contacts stream

  • Link the imported contacts stream to the Contacts stream
  • Create a sequence to provide a consistent mechanism for populating the contact UID across import from files and app updates:
    • Under the application Contacts, find Sequences
    • Right click and Add Sequence
    • Configure the sequence:
      • Name: ContactUID
      • Start Value: 10000
      • Block Value: 1
  • Open the stream configuration form for Contacts
  • Update the expression for the stream attribute UID to: nextValue('ContactUID')
  • Update all other expressions to: in.[attribute name]

Update actions to set UID from sequence

To make sure we have a consistent mechanism for setting the contact UID, we need to update the actions that update contact data to use the sequence, rather than relying on the automated mechanism they are currently using.

  • Open the Contacts app
  • Go into the configuration form for the button Update
  • Click on the quick link to bring up details for the custom action (Validate Contact)
  • Go to the Update StreamItems section
  • Add an update rule:
    • Attribute: UID
    • Expression: nextValue('ContactUID')
  • Note: you do not need to update the action attached to the Add button, because this uses the same custom action as update

Add task plan to run Contacts stream

  • Add a task plan, and within this an analysis task
  • Don't forget to enable the task plan!
  • Add the stream Contacts to the analysis task

Add button to import contacts

  • Open the app Contacts
  • Add a new button to the edit form
  • Set the name of the button to Import Contacts
  • Set the label of the button to Import Contacts

We need to create a custom action to add to this button - the custom action will run our new task plan. But we do not need to change any of the other settings on the button, since running the task plan is all we need it to do.

Create action to run task plan

  • Open the configuration form for the stream Contacts
  • Create new action:
    • Name: Import Contacts
    • Display Name: Import Contacts
    • Open the Run Task Plan section
    • Tick Run Selected TaskPlan
    • Add a task plan rule - you can do this by pressing the Image Addedbutton, but we will drag on a task plan instead:
      • Press the Image Added button
      • In the repository browser, open the application Contacts
      • Find your new task plan
      • Drag it into the list of task plan rules
      • Leave the expression blank - we want to run this task plan every time the button is pressed

Complete configuration of button - add custom action

  • Go back into the configuration for the button Import Contacts
  • Associate the custom action Import Contacts

This completes the configuration.

Try new button

Go into App Mode and try the new button. When pressed, you will see no changes. You could, as in the video, go and check in the Console or in the stream data to see what happened. But you could simply press the refresh button in the app, and you will see the imported rows added.

Make the action a refresh action

  • Open the configuration form for the grid view in the Contacts app
  • Open the section Refresh Actions
  • Press the Image Added to bring up the list of streams
  • From the repository browser, open the application Contacts, find the stream Contacts, open that to find the actions
  • Drag your new action into the list of refresh actions

Refresh test data and try again

In this exercise you will refresh the test data using rollback. This is something you will look at in more detail in the Modelling Concepts course. Just note that this is a very useful thing while developing models, but should not be used in production systems - at least not without guidance from a PhixFlow project team or PhixFlow support.

  • Right click on the stream Contacts in the model view, select Rollback Stream
  • In the rollback form, untick Keep Old Stream Sets
  • Otherwise, leave the default options - by default these will rollback only the latest run (the data loaded from the import)
  • Confirm the rollback
  • Once this is complete, refresh the data in the app, and you will see the import lines disappear

Now try your import button again - this time the imported lines will appear straight away.

File loading

To tie our import process together, we will make the import button also load a new file of contacts to import.

Widget Connector
width900
urlhttps://www.youtube.com/watch?v=32unPPMuV94&index=15&list=PLbPt6SI1Zhb_n3lXboTC_Qzq0Kg2x8LtT
height500

Update your app to load a file from the import button. To recap the steps in the video:

  • Remove the static flag from the Import Contacts stream
  • Open the configuration form for the custom action Import Contacts
  • Pin this form
  • Open the File Upload section
  • Tick the File Upload button
  • Get the tag value from the file importer:
    • From your model view, open details for the file importer
    • Copy the value in the field Tag
  • Go back into the configuration for the custom action Import Contacts
  • Paste the tag value into the field Tag Expr.

Go into App Mode. This time when you press the Import Contacts button a file upload form will appear - select the second test file and upload this. You will see the new imported contacts loaded into the app straight away.

Panel

Next chapter: 14. Workflows - context variables