/** * Get Service Request by ID. * If SR is cached, get from cache directly, * otherwise, fetch SR from EBS by sending a cURL request. * Save the SR in the in-process cache to avoid sending multiple requests to EBS. * Save the SR in the session for incident creation usage. * @param int $srID Service Request ID * @return RNCPHP\RNObject Get SR result */ function getSRDetailByID($srID) { if ($srID === null) { return $this->getResponseObject(null, null, 'Error occurs when getSRbyID :: invalid sr_id'); } // check if the SR has been cached in the in-process cache // If cached, save it in the session and return the SR $cacheKey = 'sr_' . $srID; $srDetail = \RightNow\Utils\Framework::checkCache($cacheKey); if ($srDetail) { return $this->getResponseObject($srDetail, 'is_array'); } // if not cachaed, send request to EBS server to get the SR, // and save in session and cache $extObj = 'service_request_detail'; $extAction = 'read'; $requestParams = array('srID' => $srID); $requestEntries = null; $responseFields = array('INCIDENT_NUMBER', 'INCIDENT_ID', 'SUMMARY', 'INCIDENT_TYPE', 'INCIDENT_TYPE_ID', 'INCIDENT_STATUS', 'INCIDENT_STATUS_ID', 'INCIDENT_SEVERITY', 'INCIDENT_SEVERITY_ID', 'CREATION_DATE', 'OBJECT_VERSION_NUMBER', 'SR_OWNER_ID', 'CUSTOMER_TYPE', 'SERIAL_NUMBER', 'PRODUCT', 'CUSTOMER_ID', 'CUSTOMER_PRODUCT_ID', 'INVENTORY_ORG_ID', 'EXTATTRIBUTE13', 'EXTATTRIBUTE14', 'EXTATTRIBUTE15', 'CONTACT_PARTY_ID'); $errorFields = array('FAULTSTRING', 'X_MSG_DATA'); // send curl request $getSRResult = $this->CI->model('custom/EbsApi')->sendSoapRequest($this->extConfigVerb, $extObj, $extAction, null, $this->contact, $requestParams, $requestEntries, $responseFields, $errorFields); // check the result. if success, save SR in the in-process cache and the session if ($getSRResult->error === null) { \RightNow\Utils\Framework::setCache($cacheKey, $getSRResult->result, true); $sessionKey = $cacheKey; $this->CI->session->setSessionData(array($sessionKey => $getSRResult->result)); } return $getSRResult; }
/** * Get Service Request by ID * If SR is cached, get from cache directly, * otherwise, fetch SR from Siebel by sending a curl request. * Save the SR in the in-process cache to avoid send multiple requests to Siebel. * Save the SR in the session for incident creation usage. * @param int $srID Service Request ID * @return RNCPHP\RNObject Get SR result */ function getSRDetailByID($srID) { if ($srID === null) { return $this->getResponseObject(null, null, 'Error occurs when getSRbyID :: invalid sr_id'); } // check if the SR has been cached in the in-process cache // If cached, save it in the session and return the SR. $cacheKey = 'sr_' . $srID; $srDetail = \RightNow\Utils\Framework::checkCache($cacheKey); if ($srDetail) { return $this->getResponseObject($srDetail, 'is_array'); } // if not cachaed, send request to Siebel server to get the SR, // and save in the session and cache $extObj = 'service_request_detail'; $extAction = 'read'; $requestParams = array('srID' => $srID); $requestFieldData = array('Id', 'Created', 'Abstract', 'ContactId', 'CustomerProductId', 'DefaultStatus', 'Description', 'OwnedById', 'Owner', 'Product', 'ProductId', 'SRNumber', 'SRType', 'SerialNumber', 'Severity', 'Status', 'Type', 'IntegrationId'); $responseFields = $requestFieldData; $errorFields = array('FAULTSTRING', 'X_MSG_DATA'); // send curl request $getSRResult = $this->CI->model('custom/SiebelApi')->sendSoapRequest($this->extConfigVerb, $extObj, $extAction, null, $this->contact, $requestParams, $requestFieldData, $responseFields, $errorFields); // check the result. if success, save SR in the in-process cache and the session if ($getSRResult->error === null) { \RightNow\Utils\Framework::setCache($cacheKey, $getSRResult->result, true); $sessionKey = $cacheKey; $this->CI->session->setSessionData(array($sessionKey => $getSRResult->result)); } return $getSRResult; }
/** * Create new Incident in CP using the Service Request data * @return null */ private function createIncidentBasedOnSRForSiebel() { \RightNow\Libraries\AbuseDetection::check($this->input->post('f_tok')); $data = json_decode($this->input->post('form')); if (!$data) { header("HTTP/1.1 400 Bad Request"); // Pad the error message with spaces so IE will actually display it instead of a misleading, but pretty, error message. \RightNow\Utils\Framework::writeContentWithLengthAndExit(json_encode(\RightNow\Utils\Config::getMessage(END_REQS_BODY_REQUESTS_FORMATTED_MSG)) . str_repeat("\n", 512)); } // get srID from hidden Incident CustomField siebel_sr_id $srID = null; foreach ($data as $field) { if ($field->name === 'Incident.CustomFields.Accelerator.siebel_sr_id') { $srID = $field->value; break; } } if ($srID === null) { $this->log->error('srID is NULL', __METHOD__, array(null, $this->contact)); return; } // get SR from session by srID $sessionKey = 'sr_' . $srID; $srDetail = $this->session->getSessionData($sessionKey); if (!$srDetail) { $getSRResult = $this->model('custom/SiebelServiceRequest')->getSRDetailByID($srID); $srDetail = $getSRResult->result; } // set extra Incident fields used the value of SR $data[] = (object) array('name' => 'Incident.Subject', 'value' => $srDetail['ABSTRACT']); $data[] = (object) array('name' => 'Incident.CustomFields.Accelerator.siebel_sr_num', 'value' => $srDetail['SRNUMBER']); $data[] = (object) array('name' => 'Incident.CustomFields.Accelerator.siebel_serial_number', 'value' => $srDetail['SERIALNUMBER']); if ($srDetail['PRODUCTID']) { if ($rnProduct = $this->utility->getProductByPartNumber($srDetail['PRODUCTID'])) { $data[] = (object) array('name' => 'Incident.Product', 'value' => $rnProduct['ID']); } else { $data[] = (object) array('name' => 'Incident.CustomFields.Accelerator.cp_siebel_product_validation', 'value' => "Service Request Product '{$srDetail['PRODUCT']}' can't be found in RightNow"); } } // create the Incident by calling the sendFrom function in CP core $incidentID = $this->input->post('i_id'); $smartAssistant = $this->input->post('smrt_asst'); echo $this->model('Field')->sendForm($data, intval($incidentID), $smartAssistant === 'true')->toJson(); }
<div class="rn_Padding"> <div id="rn_PageContent" class="rn_Overview"> <h2 class="rn_HeadingBar">#rn:msg:REGISTERED_PRODUCT_LBL#</h2> <div id="rn_AdditionalInfo"> <rn:widget path="output/DataDisplay" name="Asset.Name" label="#rn:msg:NAME_LBL#"/> <rn:widget path="output/DataDisplay" name="Asset.Product" label="#rn:msg:PRODUCT_LBL#"/> <rn:widget path="output/DataDisplay" name="Asset.SerialNumber" label="#rn:msg:SERIAL_NUMBER_LBL#"/> <rn:widget path="output/DataDisplay" name="Asset.PurchasedDate" label="#rn:msg:PURCHASED_DATE_LBL#"/> <rn:widget path="output/DataDisplay" name="Asset.InstalledDate" label="#rn:msg:INSTALLED_DATE_LBL#"/> <rn:widget path="output/DataDisplay" name="Asset.RetiredDate" label="#rn:msg:RETIRED_DATE_LBL#"/> <rn:widget path="output/DataDisplay" name="Asset.StatusWithType.Status" label="#rn:msg:STATUS_LBL#"/> <rn:widget path="output/DataDisplay" name="Asset.Description" label="#rn:msg:DESCRIPTION_LBL#"/> </div> <div class="rn_Questions"> <?php if (\RightNow\Utils\Framework::isContactAllowedToUpdateAsset()) { ?> <a class="rn_Questions" href="/app/account/assets/update_registered_product/asset_id/#rn:url_param_value:asset_id#/">#rn:msg:EDIT_REGISTERED_PRODUCT_CMD#</a><br/> <?php } ?> </div> <h2 class="rn_HeadingBar">#rn:msg:QUESTIONS_LBL#</h2> <div class="rn_Questions"> <rn:container report_id="230" per_page="10"> <rn:widget path="reports/ResultInfo"/> <rn:widget path="reports/Grid" label_caption="<span class='rn_ScreenReaderOnly'>#rn:msg:YOUR_RECENTLY_SUBMITTED_QS_UC_LBL#</span>"/> <rn:widget path="reports/Paginator"/> </rn:container> <a href="/app/ask/Incident.Asset/#rn:url_param_value:asset_id#/Incident.Product/<rn:field name="Asset.Product.ServiceProduct.ID"/>"/>#rn:msg:ASK_QUESTION_HDG#</a><br/>
<rn:meta title="#rn:msg:ERROR_LBL#" template="standard.php" login_required="false" /> <?php list($errorTitle, $errorMessage) = \RightNow\Utils\Framework::getErrorMessageFromCode(\RightNow\Utils\Url::getParameter('error_id')); ?> <div id="rn_PageTitle" class="rn_ErrorPage"> <h1><?php echo $errorTitle; ?> </h1> </div> <div id="rn_PageContent" class="rn_ErrorPage"> <div class="rn_Padding"> <p><?php echo $errorMessage; ?> </p> </div> </div>
private function verifyFormToken($tokenName = 'f_tok', $tokenSeed = 0) { if (!Framework::isValidSecurityToken($this->CI->input->post($tokenName), $tokenSeed)) { return $this->getResponseObject(array('redirectOverride' => '/app/error/error_id/5', 'sessionParam' => \RightNow\Utils\Url::sessionParameter()), 'is_array', Config::getMessage(FORM_SUBMISSION_TOKEN_MATCH_EXP_LBL)); } }
list($errorTitle, $errorMessage) = array("Permission Denied", "An illegal value was received for the parameter 'sr_id'"); break; case 11: // EBS server error list($errorTitle, $errorMessage) = array("EBS Server Error", "There has been an error communicating with EBS"); break; case 12: // contact_party_id and/or contact_org_id not provided list($errorTitle, $errorMessage) = array("Permission Denied", "Please set EBS Contact Party ID and/or EBS Contact Org ID first."); break; case 13: // configuration error list($errorTitle, $errorMessage) = array("Configuration Error", 'Invalid configuration setting for CUSTOM_CFG_Accel_' . 'Ext_Integrations'); break; default: list($errorTitle, $errorMessage) = \RightNow\Utils\Framework::getErrorMessageFromCode($errorID); break; } ?> <div class="rn_Hero"> <div class="rn_Container"> <h1><?php echo $errorTitle; ?> </h1> </div> </div> <div class="rn_PageContent rn_ErrorPage rn_Container"> <p><?php echo $errorMessage; ?>
/** * Handle the request to create a new Incident in CP using SR data * @return null */ private function sendFormToCreateIncidentToLinkWithSRForEbs() { \RightNow\Libraries\AbuseDetection::check($this->input->post('f_tok')); $data = json_decode($this->input->post('form')); if (!$data) { header('HTTP/1.1 400 Bad Request'); // Pad the error message with spaces so IE will actually display it instead of a misleading, but pretty, error message. \RightNow\Utils\Framework::writeContentWithLengthAndExit(json_encode(\RightNow\Utils\Config::getMessage(END_REQS_BODY_REQUESTS_FORMATTED_MSG)) . str_repeat('\\n', 512)); } // get srID from the hidden Incident Custom Field 'ebs_sr_id' $srID = null; foreach ($data as $field) { if ($field->name === 'Incident.CustomFields.Accelerator.ebs_sr_id') { $srID = $field->value; break; } } if ($srID === null) { $this->log->error('ebs_sr_id is null', __METHOD__, array(null, $this->contact)); return; } // get SR from session by srID $sessionKey = 'sr_' . $srID; $srDetail = $this->session->getSessionData($sessionKey); if (!$srDetail) { $getSRResult = $this->model('custom/EbsServiceRequest')->getSRDetailByID($srID); if ($getSRResult->error) { $this->log->error("Unable to get SR#{$srID}", __METHOD__, array(null, $this->contact)); return null; } $srDetail = $getSRResult->result; } // set extra Incident fields used the value from SR $data[] = (object) array('name' => 'Incident.Subject', 'value' => $srDetail['SUMMARY']); $data[] = (object) array('name' => 'Incident.CustomFields.Accelerator.ebs_sr_num', 'value' => $srDetail['INCIDENT_NUMBER']); $data[] = (object) array('name' => 'Incident.CustomFields.Accelerator.ebs_serial_number', 'value' => $srDetail['SERIAL_NUMBER']); $data[] = (object) array('name' => 'Incident.CustomFields.Accelerator.ebs_sr_owner_id', 'value' => $srDetail['SR_OWNER_ID']); if ($srDetail['PRODUCT']) { if ($rnProduct = $this->utility->getProductByPartNumber($srDetail['PRODUCT'])) { $data[] = (object) array('name' => 'Incident.Product', 'value' => $rnProduct['ID']); } else { $data[] = (object) array('name' => 'Incident.CustomFields.Accelerator.cp_ebs_product_validation', 'value' => "Service Request Product '{$srDetail['PRODUCT']}' can't be found in RightNow"); } } // add SR request type $srTypeMapping = $this->model('custom/ExtIntegrationConfigVerb')->getExtRequestTypeMapping(); if ($srTypeMapping === null) { $this->log->error('Unable to get request type mapping from Config Verb', __METHOD__, array(null, $this->contact)); return; } $srRequestType = $srDetail['INCIDENT_TYPE_ID']; foreach ($srTypeMapping as $type) { if (intval($type['sr_type_id']) === intval($srRequestType)) { $data[] = (object) array('name' => 'Incident.CustomFields.Accelerator.ebs_sr_request_type', 'value' => $type['inc_type_id']); break; } } // create the Incident in RNW $incidentID = $this->input->post('i_id'); $smartAssistant = $this->input->post('smrt_asst'); echo $this->model('Field')->sendForm($data, intval($incidentID), $smartAssistant === 'true')->toJson(); }
<span class="rn_DataLabel"> <?php echo \RightNow\Utils\Config::getMessage(FILE_ATTACHMENTS_LBL); ?> </span> <div class="rn_DataValue rn_FileList"> <ul> <?php foreach ($answer->FileAttachments as $attachment) { ?> <li> <a href="<?php echo $attachment->URL . '/' . $attachment->CreatedTime . \RightNow\Utils\Url::sessionParameter(); ?> " target="_blank"> <?php echo \RightNow\Utils\Framework::getIcon($attachment->FileName); ?> <?php echo $attachment->FileName; ?> </a> </li> <?php } ?> </ul> </div> <?php } ?> </div>
public function create($productID, array $formData, $serialNumber) { if (!Framework::isValidID($productID)) { return $this->getResponseObject(null, null, Config::getMessage(INVALID_ID_SALES_PRODUCT_COLON_LBL)); } //$resultSet = Connect\ROQL::queryObject(sprintf("SELECT SalesProduct FROM SalesProduct WHERE ID = %d And Disabled != 1 And Attributes.IsServiceProduct = 1 And Attributes.HasSerialNumber != 1 And AdminVisibleInterfaces.ID = curInterface()", $productID))->next(); $resultSet = Connect\ROQL::queryObject(sprintf("SELECT SalesProduct FROM SalesProduct WHERE ID = %d And Disabled != 1 And Attributes.IsServiceProduct = 1 And AdminVisibleInterfaces.ID = curInterface()", $productID))->next(); if (!($salesProduct = $resultSet->next())) { return $this->getResponseObject(null, null, Config::getMessage(INVALID_ID_SALES_PRODUCT_COLON_LBL)); } $asset = $this->getBlank()->result; if ($contact = $this->getContact()) { $asset->Contact = $contact->ID; } else { return $this->getResponseObject(null, null, Config::getMessage(CONTACT_IS_NOT_LOGGED_IN_MSG)); } if ($asset->Contact->Organization) { $asset->Organization = $asset->Contact->Organization->ID; } $errors = $warnings = array(); foreach ($formData as $name => $field) { if (!\RightNow\Utils\Text::beginsWith($name, 'Asset')) { continue; } $fieldName = explode('.', $name); try { //Get the metadata about the field we're trying to set. In order to do that we have to //populate some of the sub-objects on the record. We don't want to touch the existing //record at all, so instead we'll just pass in a dummy instance. list(, $fieldMetaData) = ConnectUtil::getObjectField($fieldName, $this->getBlank()->result); } catch (\Exception $e) { $warnings[] = $e->getMessage(); continue; } if (\RightNow\Utils\Validation::validate($field, $name, $fieldMetaData, $errors)) { $field->value = ConnectUtil::castValue($field->value, $fieldMetaData); if ($setFieldError = $this->setFieldValue($asset, $name, $field->value)) { $errors[] = $setFieldError; } } } if ($productID !== null && ($setFieldError = $this->setFieldValue($asset, "Asset.Product", $productID))) { $errors[] = $setFieldError; } if ($serialNumber !== null && ($setFieldError = $this->setFieldValue($asset, "Asset.SerialNumber", $serialNumber))) { $errors[] = $setFieldError; } if ($errors) { return $this->getResponseObject(null, null, $errors); } try { $asset = parent::createObject($asset, SRC2_EU_ASSET); } catch (\Exception $e) { $asset = $e->getMessage(); } if (!is_object($asset)) { return $this->getResponseObject(null, null, $asset); } return $this->getResponseObject($asset, 'is_object', null, $warnings); }