Pick-lists from custom objects

We have been involved in a Vault migration project in Italy, and once the import was completed, this question came across: “would it be possible to pick from custom objects in order to populate some combo boxes?”. The answer is obviously YES!

In this case, the customer manages company and contact information in Vault via custom objects. So, there is a custom object companies, with according fields, and a custom object contacts, where each contact is linked to an according company.

Now, the idea is to extend the folder creation dialog of Data Standard in order to pick from companies first, and as the company is selected, offer a list of matching contacts. The overall changes we have to apply, are similar to the one of our previous post (picking the right folder), where we also have 2 combo boxes, and while the values of the first combo are permanent, the values of the second combo are relative to the selected value from the first combo. In this case, the contacts (second combo) will be different, based on which company (first combo) has been selected. This is how my dialog looks like:

folder dialog with custom objects

There is one big difference here. We do not have properties we can bind to. In other words, the selected company and contact will be a link only. There will be no folder property that contains such selected values. We could do it, but in reality, we only want to create the link and not store the value. This implies that we cannot intercept the proper-changed event of the company in order to collect the contacts. So, we will implement the SelectionChanged event of the combo-box instead. Storing the selected values in folder properties would be possible in this case, i just want to show a different way.

So, the XAML code will have 2 labels and 2 combo-boxes. While the first combo gets the values from the function cOgetCompanies, the second combo will be set only as the user has selected a value from the first combo. To be noted, is that both combos have no binding to the SelectedValue attribute, as this will be managed via PowerShell code. Here the XAML excerpt:

<Label Content="Company" Grid.Column="0" Grid.Row="8" />
<ComboBox x:Name="cmbCompanies" Grid.Column="1" Grid.Row="8" ItemsSource="{Binding PsList[cOgetCompanies]}" />
<Label Content="Contact" Grid.Column="0" Grid.Row="10" />
<ComboBox x:Name="cmbContacts" Grid.Column="1" Grid.Row="10"/>

Now let’s have a look on the code. We basically have to apply 2 changes. One in the Default.ps1, where we call the function cOinitGetCustomObjects. Here the code:

function InitializeWindow

The second change is in the menus/CreateFolder.ps1. The link between newly created folder and the custom objects contact and company can only be done once the folder has been created. And this is why the change happens in this file:

#this is the additional code to be added at the end of the file ->
$companyID = Get-Content $env:TEMP"\cOcompanyID.txt"
$contactID = Get-Content $env:TEMP"\cOcontactID.txt"
if($companyID -ne "") { $vault.DocumentService.AddLink($companyID,"FLDR",$dialog.CurrentFolder.Id,"") }
if($contactID -ne "") { $vault.DocumentService.AddLink($contactID,"FLDR",$dialog.CurrentFolder.Id,"") }

We basically read from 2 files in the temp folder the according IDs from the company and contact. With such IDs and the new folder ID, we finally can make the link.

Now let’s have a look to the rest of the code. In oder to simplify the work, i have put all the logic into the file cOgetCustomObjects.ps1. I’m not placing here the whole code as you can download the ZIP. So, just few comments. The function cOgetCompanies searches for all company entries in the according custom object and returns a list with the company names. The function cOgetContacts collects the contacts for the selected company and returns a list of contact names. The function cOinitGetCustomObjects adds the event handlers for the SelectionChanged event of the combo-boxes and sets the values for the contacts combo. In both cases, the selected value gets stored in a text file which is used after the folder has been created in order to create the links. The reason for this is, that the execution of the context menu command and the execution of the dialog code, happen in so called different sunspaces. So, the variable available in one sunspace is not available in the second. That is why i store my IDs in simple textiles i can later reuse. If a more sophisticated solution will come across, then i will revise this section of the post, but for now “pretty simple, and it works!”.

So, once again, with some little changes in the XAML and some lines of PowerShell (Vault-API) we are able to access custom objects, and get a great benefit. Here the full sample!

Have fun!

This entry was posted in Data Standard. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s