/** * 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(); }
/** * 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(); }