Customizing the Query Result PromptBy
When defining a request offering you have the option to add different prompts used to collect information from an end user. One of the prompts available is the Query Result prompt type. A query result prompt is a control that can list the result of a query executed against the Service Manager CMDB so that a user can select resources from that list as input when making a request or when reporting an incident.
If you choose to add a query result prompt you’ll need to configure it as well. In the configuration you’ll describe which kind of objects you want to query for, which criterias they should fulfill and which data to show in the table that lists the result. One of the final options you’ll have is to choose if you want to add the selected items as either “A related item” or “An affected configuration item” (as seen in the picture below.
Now let’s say you want to add the selected objects as something else, maybe even using one of your custom relationship types?!
As it turns out, this can easily be achieved by editing the MP where you stored your request offering and doing a small modification to the XML. If open the MP you’ll find a section called “RequestOfferings”. In your request offering (use the Title attribute to make the identification of a specific request offering easier), you’ll find a section called “Targets”. Depending on which checkboxes you selected in the UI, the content of the Targets section will differ. If you’ve checked both options, as in the picture, it contains the following two targets:
<Targets> <Target Path="" OutputName="$InstanceValue$" RelationshipId="D96C8B59-8554-6E77-0AA7-F51448868B43" /> <Target Path="" OutputName="$InstanceValue$" RelationshipId="B73A6094-C64C-B0FF-9706-1822DF5C2E82" /> </Targets>
If you want to add custom relationship types as targets, it’s just a matter of copying one of the existing ones and changing the relationship id to match the relationship you want to use.
Tip: To add another target you’ll need to find get the relationship id of the relationship you want to use. This can easily be done using smlets (http://smlets.codeplex.com). Using smlets, just run the following command:
PS> Get-SCSMRelationshipClass|ft Name,DisplayName,Id
Below is an example where I’ve added two custom relationships as targets.
<Targets> <Target Path="" OutputName="$InstanceValue$" RelationshipId="D96C8B59-8554-6E77-0AA7-F51448868B43" /> <Target Path="" OutputName="$InstanceValue$" RelationshipId="B73A6094-C64C-B0FF-9706-1822DF5C2E82" /> <!--Custom Target Max Cardinality 2147483647--> <Target Path="" OutputName="$InstanceValue$" RelationshipId="53287fcd-8797-3cb5-2014-7deb12a2ed8d" /> <!--Custom Target Max Cardinality 1--> <Target Path="" OutputName="$InstanceValue$" RelationshipId="5d3e92c4-ded5-013f-e6b5-ca6f8967e672" /> </Targets>
In my request offering i list users from the CMDB. When the request is submitted a new Service Request is created and the selected user (in this case Patrik Sundqvist) is related to the request through both of the standard relationships as well as two custom ones. In the picture below you can see that four of the relationships added during the creation of the request comes from the query result prompt, these are underlined. The two that has a solid line is the standard ones (added when you check the checkboxes in the UI), the dotted lines shows the two custom relationships that I added as targets in the MP directly.
Note that the Path attribute of the Target defines which component in the type projection that should act as Source the relationship that is going to be established. If Path is empty the seed class e.g. the service request will be the source of the relationship.