Creating searches that automatically adapt to the user who runs them

11 Flares 11 Flares ×

Goal

Create saved searches that give the correct results no matter which agent runs them such as “Submitted by Me” and “My Overdue Assignments“. This is a sample application of the JavaScript injection technique taught in this previous post.

Applicability

FootPrints Service Core version 11 (any sub-release) running on Microsoft Windows Server 2003/2008/2012.

Prerequisites

  • Access to IIS on FootPrints application server
  • Access to the FootPrints file folder on the application server
  • URL Rewrite extension for IIS

Background

FootPrints Service Core version 11 has a limited number of built-in searches that dynamically apply the current user’s identity when they run. For example, all agents have access to the “My Assignments” saved search that gives each agent their respective assignments even though there is only one copy of this search. Searches like this behave as though there were an inherent “me” parameter in the assignment condition that gets filled in at runtime. There is no way to create your own searches with this capability. If you want all agents to have access to a search that shows their overdue assignments or any other custom-defined criteria, you have to create a separate search for each and every agent! As another example, you can’t create and roll out a “Submitted by Me” search to all agents; you actually have to create a “Submitted by Bob” search, a “Submitted by Jane” search, and so forth.

I was happy to see that version 12 provides a @Me placeholder you can use in the “assigned to” and “created by” conditions of a custom saved search. (For you version 12 stakeholders out there, a similar idea has been proposed on the BMC Community forum to support a @MyTeams placeholder.)  Version 11, however, requires a custom solution which I will put forth here.  

The Solution

First, you will create an advanced search and save it as “Shared (Internal)” so that other agents will be able to access it. You can define any complex criteria you need but remember to leave either the Assignee or Submitter field alone depending on which one you want to have populated at runtime when an agent runs the search.

So now you have your search, but because it has no constraint on the assignee or submitter field, it is not very useful. In order to have this constraint added at runtime, you’ll need to inject JavaScript onto the homepage for all agents. The technique I use for this is to use an URL Rewrite rule in IIS to load a custom JavaScript source file called GlobalJavascript.js. This source file will be loaded on every page in the FootPrints interface and you can put any code in it that you want. Details for this technique are offered here: Tutorial: Customizing FootPrints Service Core using JavaScript, Part 2. Assuming you aren’t already using that technique to push custom JavaScript out to the general FootPrints interface, you can create the GlobalJavaScript.js file using the code below. Otherwise, just take the parameterizedSearches function and the line that calls it from the code below and merge them into your existing file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
// DO NOT CHANGE THIS BLOCK
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = '/tmp/javascript/ResizeDocumenT.js';
    head.appendChild(script);
    function AddWindowResizeEvent() {
        setTimeout(function() { 
            AddWindowResizeEvent(arguments);
        }, 100);        
    }
// END "DO NOT CHANGE THIS BLOCK"
}
 
parameterizedSearches();
 
function parameterizedSearches() {
    // only run this customization on the homepage.
    if (document.location.pathname.search('/MRcgi/MRhomepage.pl') == -1) {
        return;
    }
    // INSTRUCTIONS:
    // Populate the "searchesToParameterize" list with the searches that should take a parameter 
    // at runtime for either the assignee or submitter condition. 
    // The ids for searches can be found in \etc\SearchList. 
    // The id for cross-workspace searches can be found in \etc\crossProjectSearches\SearchList*.txt 
    var searchesToParameterize = [ 
        { 
            searchId: '1:PROJECT:SEARCH:Open__bassigned__bto__bme', 
            parameter: 'assignee' 
        },
        { 
            searchId: '1:PROJECT:SEARCH:Created__bby__bMe__blast__bmonth', 
            parameter: 'submitter' 
        }
    ]; 
 
    var mapParam = { 
        submitter: 'ORIGINATOR', 
        assignee: 'ASSIGNEDTO' 
    }; 
 
    if (document.dropDown != undefined && document.dropDown.SAVEDNAME != undefined) { 
        originalProcessDisplayDropdown = processDisplayDropdown; 
 
        processDisplayDropdown = function(refresh, useMaxMinInc, isMobile) { 
 
            var form = document.dropDown; 
 
            var selectedSearch = form.SAVEDNAME.value; 
 
            // See if the selected search matches any that should be parametrized 
            var parametrizedSearch = null; 
            for (var i = 0; i < searchesToParameterize.length; i++) { 
                var id = searchesToParameterize[i].searchId; 
                // cross-workspace searches do not begin with number 
                if (id.match(/^\d/) == null) { 
                    id = "CROSSPROJ:" + id; 
                } 
                if (selectedSearch.indexOf(id) == 0) { 
                    parametrizedSearch = searchesToParameterize[i]; 
                    break 
                } 
            } 
 
            if (parametrizedSearch !== null) { 
                var input = document.createElement('input'); 
                input.type = 'hidden'; 
                input.name = mapParam[parametrizedSearch.parameter]; 
                input.value = form.USER.value; 
                form.appendChild(input); 
            } 
 
            originalProcessDisplayDropdown(refresh, useMaxMinInc, isMobile); 
        }; 
    } 
}

At line 28, I have configured this customization to run with 2 saved searches. You need to replace this code so that it lists your own search(es). Each search is listed as an object (within { } braces) having a searchId property and a parameter property. To find the searchId property for your saved search, you’ll have to open the \etc\SearchList file under the main FootPrints folder on your server. This file is a bit difficult to read, so here are some tips: Each line of the file represents a saved search or report. Each line contains 4 tokens (pieces of data) separated by colons. The first token is the ID of the workspace to which the search/report belongs. The second token is the owner — the term “PROJECT” indicates that the search/report is shared for agents to access.  The next token should read “SEARCH” for searches, “FORMAT” for reports, or “TIME” for time tracking reports, and the final token is the search’s name with spaces and other characters encoded as ‘__b’, etc.

The parameter property should be either 'assignee' or 'submitter' depending on which field you want to provide dynamically using the id of the agent running the search.

You can add as many of these objects as you want, but remember to separate them with commas. Here’s what that area of code would look like if you only wanted to include 1 search:

var searchesToParameterize = [ 
    { 
        searchId: '1:PROJECT:SEARCH:Open__bassigned__bto__bme', 
        parameter: 'assignee' 
    }
];

and here’s what it would look like if you had 3 searches:

var searchesToParameterize = [ 
    { 
        searchId: '1:PROJECT:SEARCH:Open__bassigned__bto__bme', 
        parameter: 'assignee' 
    },
    { 
        searchId: '1:PROJECT:SEARCH:Created__bby__bMe__blast__bmonth', 
        parameter: 'submitter' 
    },
    { 
        searchId: '1:PROJECT:SEARCH:My__bOverdue__bTickets', 
        parameter: 'assignee' 
    }
];

Caveats

Once you’ve created a saved search and set up the JavaScript file and the URL Rewrite rule that sends the JavaScript to the agents’ web browsers,  you can tell your agents to include the search(es) on their homepages by changing their Preferences. To run the search, the agents would simply select the search from the list on their homepage as they normally would:

saved search There are a few caveats to be aware of, however:

  • This customization is desiged to work for agents only, not customers.
  • The runtime substitution of the agent’s ID into the search only takes place when the search is run by selecting it from the list on the homepage. If an agent has the search set as their default search, the custom behavior won’t take place when the agent first logs in or clicks the Home button.
  • The custom behavior will not occur if one of the searches is launched from the My Searches page (although the user can get the correct behavior by clicking the refresh icon after the search comes back with its results.)
  • With the code provided above, only the assignee and submitter fields can be supplied at runtime. Adding support for any arbitrary field is possible but beyond the scope of this sample.

Need help?

For help writing a FootPrints Service Core customization, or to discuss a project that might require a custom solution, contact RightStar Technical Services.

Disclaimer

In no event shall RightStar Systems, Inc. or its employees be held responsible for loss or damages arising out of the use, inability to use, or the results of use of, the information and source code contained in this article. The information and materials contained or referred to in this article are for reference only. RightStar Systems, Inc. and its employees make no warranty of any kind regarding the information and source code in this article. In no event shall RightStar Systems, Inc. or its employees be obligated to provide additional support on the topic discussed in this article.

 

11 Flares Twitter 2 Facebook 1 LinkedIn 8 11 Flares ×

Leave a Reply

Show Buttons
Hide Buttons