Module 4

Add code lists manually, programmatic and dynamically

In this module you’re expanding the application you made in the previous modules to support more of the requirements of the municipality of Sogndal.

Topics covered in this module:

  • Code lists/Options
  • Dynamic

Tasks

In many applications there is a need to provide the user with a set of response options for a data field. The answer options are referred to as code lists or options.

In Altinn Studio this is supported in the form of radio buttons, checkboxes and dropdown lists.

There are three ways to set up code lists in Altinn today

  1. Directly on the component through Altinn Studio or manually in FormLayout.json*
  2. In a static json-file referred to in the component
  3. Programmatically through application logic (only available for radio buttons and check boxes)

In this task, you will get to try out all three ways to set up a code list.

The municipality of Sogndal wishes to collect information on the newcomers working situation. Some of the data they wish to collect is which sector and industry the newcomer works in, and how many years the newcomer has been active in the workforce.

In Altinn Studio

  1. Create a new form page to collect data about working conditions

  2. Set up a radio button component for Sector. Create the answer options Offentlig and Privat manually.

  3. Set up a check box component for Industry. Choose Kodeliste as method for adding checkboxes and add Kodeliste ID industry

    The rest of the setup for this component is done locally

  4. Set up a dropdown list for Years in work force Add Kodeliste ID years-in-work-force

    The rest of the setup for this component is done locally

  5. Commit and Push your changes to master, and Pull the changes to your local development environment.

In Local Development environment

  1. The municipality of Sogndal has created a code list for industries. Download the file and place it correctly in the repository.

  2. Set up the values in the code list for Years in work force directly in a new C# class.

    Answer options:

    LabelData value
    0 - 5 years0-5
    5 - 10 years5-10
    10 - 20 years10-20
    20+ years20+
  3. Verify that all code lists works as expected.

Useful documentation

Knowledge check

  • What is the difference between static and dynamic options?
  • What will the area of use be for secured dynamic options?

In some cases the values displayed in a code list may be attached to a different field in the form.

The municipality of Sogndal wants the list of industries to choose from to be personalised based on which sector the user works in.

Requirements from the municipality

We want the user to be presented with a different set of options for the industry choice based on which sector they work in.

Useful documentation

Knowledge check

  • If a list of options is set up with mapping towards the data model - what happens when the field in question changes value?
  • What happens with the chosen value on a field connected to an option-list that is retrieved over again from the server side?

Requirements from the municipality

If the user chooses IKT (data/it) under industry, a text with a link to our overview of vacant positions should appear.

  • Below the industry choice, the following text should appear

    Vi ser at du besitter kompetanse vi trenger i kommunen.
    Se en oversikt over våre ledige stillinger her.
    
  • Line 2 in the text should be a link that directs to: https://sogndal.easycruit.com/index.html

The text and link should only be visible if the user has chosen IKT (data/it).

Useful documentation

Knowledge check

  • If you add a new function to RuleHandlerHelper - where will it run?
    • Would dynamic work without this defined?
  • What is the correlation between functions defined in RuleHandlerObject and the file RuleConfiguration.json?

Summary

In this module you have set up the dropdown list, radio button and checkbox components and added options for them manually, programmatically and dynamically.

The service should run on your local computer with local test and it should be possible to select the expected option from each component.

Remember to push your local changes, so that they are available in Altinn Studio when you’re happy with them

Solution

If you did not manage to complete all the steps, we have an example solution that you can use as inspiration.

Screenshot of collection of work information for private sector Screenshot of collection of work information for public sector