Enhancing our New Order view to use associations


The requirements call for someone with the Meal Program Member Role to be able to submit an order for a specific dish. 

Cleaning up the view

In the earlier exercise, we built a very simple view called New Order, but this didn't use any information about Restaurant or Dish records. Also, before we forget, make sure that this view has granted access to the Order Submitter role.

Now to add support for ordering a dish. This is easy to fix. When we last saw our New Order view, it looked something like this:

Hi

We see that the user puts some text into the Description field (originally called Details in this view) and submits. The order is more complicated now, however, in several ways:

  • The user picks the Requested Date. 
  • It needs to be associated with a Dish (that happens to be associated with that Restaurant).  The Order will no longer uses the Details Field; we are going to retire it. That is now replaced by its association to Dish.
  • It needs to be associated with a Restaurant. This is also new.
  • It can be associated with multiple People Records; another new feature.
  • The record grid should show more relevant details.

The view we are building here will look like this (the actual position of the fields is somewhat up to you).

New Order - Employee Association Preview 3.PNG

Luckily, all of these things are very easy to do because we have set up the data model very nicely, and we can use a powerful view component that we haven't touched on yet, called Association.

We will need to clean up the fields:

  • Mark the Details (that is, the Description) field as Hidden At all times. We are not currently going to use it, though eventually it might be useful to generate some kind of "one-line" description of the order automatically. To avoid validation errors since this field is required, you can set a default value in the Value property

new order default value.png

  • If necessary, add the Requested Date field (or make sure the Hidden switch is cleared if it was already there).
  • Add the Special Instructions field.

Since we will be adding new components, we can improve the experience by laying them out in a multi-column way.  You already know how to do this: by adding a Container component.  The difference here is that you can drag it directly into the record editor component for the order, make it 2 columns, then drag the Date Requested field into the left side (leave the right side empty for the moment). The hidden fields' position in the layout does not matter.

New Order View Fix Fields.png

Adding dropdowns for Restaurant and Dish associations

For the associations to a single record, like Restaurant and Dish, the idea is that the user will pick Restaurant from a dropdown list, and based on that selection, will the pick the Dish. Both of these are done by adding an Association component and configuring it to act like a dropdown.

Let's think about what this means. Consider the data model we came up with during analysis; recall that there is a third association involved here: the one that constrains selection of a Dish to be associated with a given Restaurant. The following diagram shows the relationships involved.

Three-way Association Constraints

Logically, we would only use a dropdown UI for selection when there is exactly one record on the other side (the "one" side of the relationship).  The second dropdown would in effect be a "cascading picklist" based on the selection of the first one.

Drag in a Association component from the Palette directly into the record editor for Order. At first, it does not look like a dropdown, but this changes once the Association editing mode option is picked. As you want to see all the Restaurants, so we will leave the Filter by association as blank.

New Order - Restaurant Pulldown.PNG

Now repeat this to create a Dropdown for Dish.  Note the additional properties exposed for Filter by association.

New Order - Dish Pulldown.PNG


When you specify the record ID associated with Filter by association, be sure to pick the ID from the Associations part of the Edit expression dialog. The full "path" is 

View > Components > Record editor (Order) > Associations > Restaurant fulfills orders > First associated record > ID

New Order - Dish Pulldown Filter Associated Record.PNG

At this point you can save and refresh your preview (or shell). If you have created some Restaurant and Dish data (using the Restaurants View you have completed earlier), you will see them appearing in the dropdowns. The Select a restaurant: dropdown shows every Restaurant, and Select a dish: only shows the Dish Records that are associated to the Restaurant.

New Order - Restaurant and Dish Preview.PNG

Associating people to the order

Of course, we aren't done with associations. Recall the requirement that Maria can specify a list of persons who will be consuming the lunch.

Once again, the Association component comes to the rescue; but this time we won't use the Association editing mode of Dropdown, because there are more than one possible People record to be associated. It does require that there be a view already created that has an output parameter that returns a set of selected People records.


Let's create a simple view to select People (Container layout), let's call it People Search:

Use a grid to display the People, searching for the BMC Helix ITSM form CTM:People (you can use the magnifying glass icon in the Record definition name to search for this form),

select people grid.png

In Edit grid columns, select Full Name:

select people.png

As we have seen before, let's add an Output parameter to our view, it will contain the People selected that will be assigned to the Order. Let's call this Output parameter Selected People.

The Source will be our grid Selected rows:

select people output parameter.png


Let's add a Button bar and an Action button named Select People.

This Action button has a simple action Close view.

select people close button.png

select people close.png

Closing the view will automatically set the Record grid Selected rows in the view Output parameter Selected People.


Re open the view Simple New Order and let's configure it to use our new view.

This time, drag a new Association component to the right side area. Configure the Record definition to associate.

Tip: recall that the easiest way to find definitions in Innovation Studio, or in BMC Helix ITSM, is to search for them:

image2018-10-24_15-19-10.png


The rest of the properties are straightforward . As there is no Many:1 association selected these records, it doesn't even offer you the Dropdown option.

image2018-10-24_15-21-28.png

You will find that the Association component comes with quite a bit of built-in functionality that handles this case very nicely. You can try it out when you save and refresh your preview (assuming you have created or imported some People records in the BMC Helix Foundation - if not there will be none to select from).

New Order - Employee Association Preview 1.PNG

A blade with the People Search view appears. If any records have been defined, they will appear here (if not, you can go to the Mid-Tier Applications > Administrator Console > Standard Configuration TAB > People create button and create a few). Select some People records and click the Select People button.

New Order - Employee Association Preview 2.PNG

When you click Select People in the blade, the associations to People are created in a state that reads to the user as Pending.  Once the order is submitted, the associations are created on the back end at the same time as the Order record instanceIf you haven't done so already, be sure there is a Refresh action as part of the order's Save button actions, so that after the Order is submitted, the record grid is automatically refreshed.

Use associated data in the record grid

Make the following changes to the record grid configuration:

  1. Remove the Details column (we are no longer using that field).
    1. You will need first to make sure that the Order record definition Description field has a Default value set, for example New Order.
  2. Add the restaurant name:
    1. You will find it in the Associations tab of the Available columns in the Edit grid Columns dialog.
    2. Drag it in as the column identified by Restaurant Fulfills Orders > Name
    3. Because the user will just think of this as the restaurant name, change the Label to Restaurant
  3. Add the dish name using very similar steps to the above.

You should now have a completely functional, revised New Order view that understands associations.

What we learned

Because the association definitions were already in place, creating this functionality was actually a bit of a breeze. We learned that:

  • Fields within a record editor can be layered out using container components too.
  • Action buttons can similarly be placed within a record editor's layout.
  • You can use the Association component as a dropdown to allow users to select a single associated record.
  • You can also filter it the Association component to create a "cascading" effect when associations between the selected records themselves are defined.
  • You can use the Association component as a special list UI that can use a configured view for selecting "many" records to associate.

Maria now has a way of creating an Order record and specifying a Dish, and multiple People records for it.  We could imagine a much improved view that allows Maria to "shop for" a Dish and then create an associated Order. However, that gets a bit more complicated and we will leave that as a project for the reader.

Now let's turn to the last view we need in order to fully enable the Order Lifecycle Process to handle the requirements - namely, a view that shows order status and lets users update it.




 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*