This is for sure one of my favorite posts!
And in the spirit of sharing, here’s a client relevance code snippet that I use based on brolly33’s structure/approach here to automatically generate a session relevance statement given a list of desired property names (input via a file). It is especially handy if you have a relatively long list of properties you’d like to return to avoid having to manually build the session relevance statement by hand. For instance, I used this approach to automatically generate a session relevance statement to return data from over 100 properties at once! (Not something I’d generally recommend, but it worked for my use case).
/* efficient session relevance builder */
/* based on John Talbert's blog - https://www.ibm.com/developerworks/community/blogs/e9d21113-aa93-467e-ac77-a0d20a21eaec/entry/Session_Relevance_Computer_Properties_query_Efficiency?lang=en*/
/* be sure to update the *3* references to the file name/path containing the desired property names */
("(";
"name of item 0 of it | %22missing name%22";
(", (concatenation %22;%22 of values of results (item 0 of it, elements of item " & it & " of it))") of (integers in (1,(number of lines of file "R:\Properties.txt")) as string));
") of (";
"elements of item 0 of it";
(",item " & it & " of it") of (integers in (1,(number of lines of file "R:\Properties.txt")) as string);
") of (";
"set of BES computers";
(", set of bes properties whose (name of it as lowercase = (%22" & it as trimmed string & "%22) as lowercase)") of lines of file "R:\Properties.txt";
")"
So, for instance, if you create a file called “R:\properties.txt” with the following contents:
Computer Name
OS
CPU
RAM
Free Space on System Drive
The result of the Client relevance would be the following Session relevance:
(
name of item 0 of it | "missing name"
, (concatenation ";" of values of results (item 0 of it, elements of item 1 of it))
, (concatenation ";" of values of results (item 0 of it, elements of item 2 of it))
, (concatenation ";" of values of results (item 0 of it, elements of item 3 of it))
, (concatenation ";" of values of results (item 0 of it, elements of item 4 of it))
, (concatenation ";" of values of results (item 0 of it, elements of item 5 of it))
) of (
elements of item 0 of it
,item 1 of it
,item 2 of it
,item 3 of it
,item 4 of it
,item 5 of it
) of (
set of BES computers
, set of bes properties whose (name of it as lowercase = ("Computer Name") as lowercase)
, set of bes properties whose (name of it as lowercase = ("OS") as lowercase)
, set of bes properties whose (name of it as lowercase = ("CPU") as lowercase)
, set of bes properties whose (name of it as lowercase = ("RAM") as lowercase)
, set of bes properties whose (name of it as lowercase = ("Free Space on System Drive") as lowercase)
)
This can be tweaked fairly easily to work with Property IDs rather than names as well in cases where that’s needed.