-
Notifications
You must be signed in to change notification settings - Fork 4
Workgroup Code Examples
nlil edited this page Jul 17, 2012
·
6 revisions
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);
?>
###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";
}
?>