Skip to content

Workgroup Code Examples

nlil edited this page Jul 17, 2012 · 6 revisions

Retrieving Remedy workgroup data

There are three methods for fetching Remedy workgroup data. One searches by the workgroup's ID number. The second searches by the workgroup's name. The third allows for searching using an arbitrary query.

###Searching by workgroup id.

<?php

/***************************************************************  
 *  
 * Example: Lookup a Remedy workgroup by the workgroup ID number
 *  
 ***************************************************************/

require_once 'Ncstate/Service/Remedy.php';

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

// the workgroup ID number  
$workgroupId = '1036';

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

print "Workgroup name is: $result->group_name \n";
print_r($result);

?>

###Searching by workgroup name

<?php

/***************************************************************  
 *  
 * Example: Lookup a Remedy workgroup by the workgroup name
 *  
 ***************************************************************/

require_once 'Ncstate/Service/Remedy.php';

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

// the workgroup name... almost always in UPPER CASE
$wgName = 'REMEDY';

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

print "Workgroup ID number is: $result->group_id \n";
print_r($result);

?>

Retrieving workgroup information based on a query

The workgroupList 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 workgroups can be found below.

###Searching using a query

<?php

/***************************************************************  
 *  
 * Example: Search Remedy workgroups 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 = "'Status' = \"Current\" AND 'SurveyPercent' != null";

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

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

$wgCount = count($workgroups);
print "Query returned $wgCount workgroups.\n";
print "Workgroup names:\n";
foreach ($workgroups as $wg) {
    print $wg->group_name . "\n";
}

?>
Clone this wiki locally