Display DataType Item as Dropdown list in Forms

Hi community,

does somebody knows a way to display the DataType 'Item' like a List dropdown?

I currently modify a change process and want to use a team dropdown instead of the current team item selector. Of course I can define a separate list for my teams and use this one for my dropdown. The selected team from the dropdown could than be used as team_id.

But this would require that my teams are duplicated. I have to maintain teams in the List and the Team ItemType. For teams this still would be ok, but I want to do something similar for Identities. 

Any ideas?

Angela

  • Hi Angela,

    You'll need to write a bit of custom code to use a dropdown field for an Item property, but it's pretty easily possible. You would need to add a new dropdown field to your Form that isn't explicitly linked to any property. You could then use an onLoad or onFormPopulated form event to dynamically set the values of this dropdown field. You'll also need to use an onChange field event to actually set the value of the property on the item after the user makes their selection.

    I'd recommend checking out the first use case in this blog post for some sample code on dynamically setting the values of a dropdown based on an item query. One thing to keep in mind for your use case of using this dropdown for an Item property is that you'll want the value of the list elements you add to be equal to the ID of the team items you populate that list with.


    Chris

    Christopher Gillis

    Aras Labs Software Engineer

  • Hi Chris,

    thanks again for your help! I can confirm that this variant works well. I right now have a nice process that changes the Team drop down based on Impact Matrix changes. The selected team is duplicated to the team_id and set´s a couple of reviewers based on team roles.

    But right now I need an additional list for the teams. Each time when I create a new Item in ItemType Team, I also have to add this one to the List used for the drop down. Is it somehow possible avoid the additional list? For the "team" use case, this solution works very well. But I am also thinking about using drop downs for the reviewers, as we sometimes have two identities for a certain team role. I do not want to build additional (filter) lists just for storing identities. There are too many of them. 

    Angela

  • Hi Angela,

    Using a JavaScript method like the one outlined in the blog post, you can use any source of data to populate a dropdown. There's no need to duplicate the data inside of a List. For example, the code below populates the dropdown with all of the Team items in the database. The name of the Team is used as the label of an option and the id is used as the value.

    var dropdown = getFieldComponentByName('teams');
    var teams = aras.IomInnovator.newItem("Team", "get");
    teams.setAttribute("select", "id, keyed_name");
    teams = teams.apply();
    // List that will be passed into the dropdown control for typeahead functionality
    listOfTeams = [{
      label: '',
      value: ''
    }];
    // Add an entry to our list for each Team
    for (var i = 0, teamCount = teams.getItemCount(); i < teamCount; i++)
    {
      var team = teams.getItemByIndex(i);
      listOfTeams.push({
        label: team.getProperty("keyed_name"),
        value: team.getProperty("id")
      });
    }
    dropdown.component.setState({list: listOfTeams});

    After a user makes their selection in this dropdown list, you can retrieve the value by using getFieldComponentByName("YOUR_FIELD_NAME").component.state.value;. In this case, because we've set the value of our options to be the ID of the teams, this will return the ID of the selected team.

    Using this approach, the only limit to what can be populated inside of a dropdown is the ability to query for the information. :)


    Chris

    Christopher Gillis

    Aras Labs Software Engineer

  • Hi Chris,

    thanks for the detailed answer! I was out of office last week and didn´t had the chance to test it.

    Your code is a pretty cool replacement for the regular team item selector. The drop down works excellent in combination with the team_id data source. 

    Displaying all teams in the drop down is fine, but maybe not the best choice for every ItemType (too much content...). But one very good use case is when we want to dynamically filter the drop down without a separate filter list.

    I think I will do the following: The ItemType Team is not a Core Item. We can use the classification property in the Team ItemType to assign some additional information about the teams. So we can assign a suitable filter property directly to Teams and can avoid the Filter List with the same content.