Editing the XML of a view to alter the criteria to include AND instead of OR

Another time when some XML editing comes in handy is when you're trying to create some more customized views. Sure, you're able to create views from the console, but the Create View dialogue doesn't allow you to do things such as renaming column headers, set the order of columns, or something as simple as creating a view criteria that includes the same property twice, constructed with an AND instead of OR.

In this recipe, we will do just that - modify the view criteria through some XML editing so it is constructed with an AND instead of an OR.

Getting ready

In order to follow this recipe you will need to create a view from the console for us to edit in XML:

  1. Start the Service Manager console and go to the Work Item workspace.
  2. Right-click Incident Management and select Create View.
  3. As the Name of the view, enter All Active Incidents and select a management pack to store the view in.
  4. Click on Criteria on the left side of the dialogue window to get to the Criteria section. Click Browse and select the Incident class.
  5. Now, locate and add Status twice to the Criteria. Set the first row to Status Does Not Equal Resolved and set the second row to Status Does Not Equal Closed. Notice how Service Manager has added an OR between these two rows.
  6. As the criteria is constructed right now, it will always show all incidents regardless of status - just because of the OR.

    Getting ready

  7. Proceed to the Display section and select the following properties:
    • Classification Category
    • Created Date
    • ID
    • Last Modified
    • Status
    • Support Group
    • Title
  8. Click OK to create the view.

How to do it...

So we have our view that we need to edit in order to work, this is how you would fix the criteria:

  1. Open Service Manager and go to Management Packs in the Administration workspace.
  2. Locate the management pack in which the view you want to edit is stored, and Export it.
  3. Open the management pack with your favorite XML editor - in my case Notepad++.
  4. Now we need to locate our specific view within this management pack, in order to do so, search for All Active Incidents. This should take you to the DisplayStrings section of the management pack, which should look similar to this:
          <DisplayString
          ElementID="View.baa0288a02d149b4a2f8e5124dc4e247"> 
          <Name>All Active Incidents</Name> 
          </DisplayString> 
    
  5. Unless you have several views named All Active Incidents, this piece of code gives us the ElementID to our view. Copy the ElementID (in my case View.baa0288a02d149b4a2f8e5124dc4e247) and do a search for this until you find a row starting with <View ID= When you've located that row, you've found the actual view definition of the All Active Incidents view.
  6. Scroll a couple of rows down until you find the <Criteria> tag. This is where the view criteria is defined.
  7. Within the criteria, you should see a couple of <Expression> tags, but there should also be a tag called <Or> and another one called </Or>. The code between these two tags are the code that defines that the Status Should Not Equal Resolved or Status Should Not Equal Closed.
  8. In order to change the criteria from OR to AND, simply replace the Or in the tag to And. Then save your management pack.

    How to do it...

  9. Open the Service Manager console and go to Management Packs in the Administration workspace.
  10. Import the management pack that we just edited and the view criteria should be updated.

In order for our changes to apply, you might need to restart your Service Manager console since the view might be cached.

How it works...

After you've made the change in the management pack by editing the XML and re-imported it into Service Manager, the view criteria should now contain an AND instead of an OR.

To see how our changes are reflected in the console, locate the All Active Incidents view, right-click it, and then select Edit View. Now if you go to the Criteria section of this view, there should now be an AND instead of the OR, but what is also worth noting, is that the criteria section is now disabled. This is because we've edited the criteria directly in the management pack and that the Edit View wizard doesn't support the modification.

How it works...

There's more...

There are plenty of other modifications that you can do to views by doing some XML editing - as mentioned earlier changing column names and order is two of them. You might also change things such as column width, how sorting should be handle in different columns, the view icons, and so on.

See also

See the following recipe on how to do some other XML editing:

  • Using an XML editor to modify management packs
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset