Skip to content
nlil edited this page Jul 17, 2012 · 5 revisions

Retrieving Remedy user data

Remedy "users" are the folks who can actually login to the Remedy system... not to be confused with the Remedy customers.

There are four methods available for manipulation Remedy user data:

  • Lookup a Remedy user by their Remedy user ID number (userGetByUserID)
  • Lookup a Remedy user by their Remedy user name (userGetByLogin)
  • Update a Remedy users information (userUpdate)
  • Search Remedy users using an arbitrary query (userList)

###Searching by Remedy user ID number.

<?php

/***************************************************************  
 *  
 * Example: Lookup a Remedy users by the user's ID number
 *  
 ***************************************************************/

require_once 'Ncstate/Service/Remedy.php';

// create a new Remedy object  
$remedy = new Ncstate_Service_Remedy($user, $pass);

// the users ID number  
$userId = '449';

try {
    $result = $remedy->userGetByUserID($userId);
}
catch (Ncstate_Service_Exception $e) {
    die('An error occurred while getting the user:' . $e->getMessage());
}

print "User login name is: $result->login_name \n";
print_r($result);

?>

###Searching by Remedy user login name

<?php

/***************************************************************  
 *  
 * Example: Lookup a Remedy users by the user's login name
 *  
 ***************************************************************/

require_once 'Ncstate/Service/Remedy.php';

// create a new Remedy object  
$remedy = new Ncstate_Service_Remedy($user, $pass);

// the user's Remedy login name
$userName = 'nlil';

try {
    $result = $remedy->userGetByLogin($userName);
}
catch (Ncstate_Service_Exception $e) {
    die('An error occurred while getting the user:' . $e->getMessage());
}

print "User's ID number is: $result->user_id \n";
print_r($result);

?>

###Update a Remedy user's information

<?php

/***************************************************************  
 *  
 * Example: Updating a Remedy user record  
 *  
 ***************************************************************/

require_once 'Ncstate/Service/Remedy.php';

// create a new Remedy object
$remedy = new Ncstate_Service_Remedy($user, $pass);

// The userId of the user we wish to update  
$userId = "256";   // tester

// A possible user update.
$userInfo = array(
    'availability' => 'No', // Going on vacation... don't bother me  
);

/*
    'availability'             // user available: Yes | No
    'default_notify_mechanism' // user’s default notify mechanism: None | Alert | Email | Pager
    'email_address'            // user's email address for notifications, etc.
    'email_signature'          // user’s email sig.
    'initial_query'            // query to issue automatically issue at login (Windows client only)
    'pager_address'            // email address of user’s pager
    'pager_template'           // user’s preferred pager notification format template
    'password'                 // user's Remedy login password
    'products_count'           // max number of products in user’s personal products menu
    'solutions_count'          // max number of solutions in user’s personal solutions menu
*/

try {
    $remedy->userUpdate($userId, $userInfo);
}
catch (Ncstate_Service_Exception $e) {
    die('An error occured while updating the user:' . $e->getMessage());
}

// Fetch the user record back to make sure we succeeded
try {
    $result = $remedy->userGetByUserID($userId);
}
catch (Ncstate_Service_Exception $e) {
    die('An error occurred while getting the user:' . $e->getMessage());
}

print "Availability for $result->login_name is: \"$result->availability\" \n";

?>

Retrieving Remedy user information based on a query

The userList method has the same structure as all of the search methods. These methods have one required field -- the search query -- and two optional fields: a start offset, and a max limit. The offset is simply the index of the starting entry and the max limit will limit the returned list of Ids to the specified number. Search methods return only object Ids, instead of actual objects. To retrieve a list of actual objects, loop through the Ids, call a get method with the object's Id and add the returned object to a new list.

Note: the search method will return different objects depending on how many objects are returned. If there is just one object, the search method returns the object. If the number of objects returned is greater than 1, the object returned will contain all of the entries in a "getListValues" variable. In this case, you must iterate over getListValues to retrieve the object Ids (see below).

Queries

Remedy expects queries to have a very specific format. The overall format is the following:

'[label]' [operator] "[value]"

The label is a predefined keyword in the database (see the list below for expected labels and their value formats).
The value should correspond to the label format (i.e. dates formated correctly, etc.) The operator can be any of the following: =, !=, <, <=, >, >=, LIKE You can concatenate conditions using AND or OR operators between conditions.

A summary of the search terms allowed when searching for users can be found below.

###Searching Users using a query

<?php

/***************************************************************  
 *  
 * Example: Search Remedy users by specified qualification
 *  
 ***************************************************************/

require_once 'Ncstate/Service/Remedy.php';

// create a new Remedy object  
$remedy = new Ncstate_Service_Remedy($user, $pass);

// formulate the query
$qual = "'Availability' = \"Yes\" AND 'License Type' = \"Fixed\"";

try {
    $userList = $remedy->userList($qual, 0, 0);
}
catch (Ncstate_Service_Exception $e) {
    die('An error occurred while getting the user:' . $e->getMessage());
}

$users = array();
// check if the return value has any entries  
if (isset($userList)) {
    /*  
     * Single entry lists are structured  
     * differently than multiple entry objects. We must  
     * therefore check for multiplicity and handle both  
     * cases.  
     */
    if (count($userList->getListValues) > 1) {
        foreach ($userList->getListValues as $user) {
            $users[] = $user;
        }
    } else {
        $users[] = $userList;
    }
}

$userCount = count($users);
print "Query returned $userCount users.\n";
print "User names:\n";
foreach ($users as $user) {
    print $user->full_name . "\n";
}
// print_r($users);

?>

Search terms for the User form

Availability => Yes | No | Retired
BMC Modified Date => date-time
NCSU Modified Date => date-time
Default Notify Mechanism => None | Alert | Email | Pager
DefaultGroup => string
Email Address => string
EmailSig => string
Request ID => string
Full Name => string
Group List => string
InitQuery => string
BMC Last Modified By => string
NCSU Last Modified By => string
License Type => Read | Fixed | Floating | Restricted Read
Login Name => string
MenuName => string
PagerAddress => string
PagerTemplate => string
ProductsCount => int
SolutionsCount => int
SupportPartner => Yes | Probation | No | Retired
UserID => int