Document toolboxDocument toolbox

(v1) Service Now Integration - Remove Service

Service Now Integration is built upon PCR-360's (v1) Custom API Endpoints. Service Now will send its requests to the appropriate Endpoint and PCR-360 will process the details accordingly.

SNOW: Remoce Service
<?php
// log the original request JSON in the SERVICENOW_DETAILS UDF table
$details = ["data" => []];
$systemValues = [
    "apikey" => "apikey",
    "typeformat" => "typeformat",
    "module" => "module",
    "controller" => "controller",
    "action" => "action",
    "request_method" => "request_method",
    "limit" => "limit",
    "page" => "page",
    "tenants_recid" => "tenants_recid",
    "ident" => "ident"
];
$data = array_diff_key($request, $systemValues);
foreach ($data as $field => $value) {
    $details["data"][] = [
        "LABEL" => $field,
        "VALUE" => $value
    ];
}

// set the default save data to create an SO with the SNOW data in a UD table
$payload = [
    "type" => "SO",
    "csr" => "1", // User Demo
    "udf_SERVICENOW_NUMBER" => trim($request["servicenow_number"]), // SERVICENOW_NUMBER
    "udf_SERVICENOW_DETAILS" => json_encode($details), // SERVICENOW_DETAILS
];

// get the requestor based on the incoming requestor email address
$requestorQuery = $this->query(
    "SELECT 
        C.RECID 
    FROM 
        CONTACTS C
    JOIN CONTACTS_EMAILS CE ON C.RECID = CE.CONTACTS_RECID
    WHERE 
        CE.EMAIL = :requestor",
    [":requestor" => trim($request["requestor"])]
);

if (count($requestorQuery) && ($requestorRecid = $requestorQuery[0]["RECID"])) {
    // find the service RECID
    $service = $request["service"];
    $serviceQuery = $this->query(
        "SELECT
            S.RECID
        FROM
            SERVICES S
        WHERE 
            S.SERVICE_ID = :service
            OR S.SERVICE_ID_FMT = :service",
        [":service" => $service]
    );

    if (count($serviceQuery) && ($serviceRecid = $serviceQuery[0]["RECID"])) {
        // set the SDA variables if the data is valid
        $payload["sd_action"] = "REMOVE";
        $payload["requestor"] = $requestorRecid;
        $payload["service"] = $serviceRecid;
    } else {
        $response["error_message"] = "A valid SERVICE RECID could not be found based "
            . "on the incoming Service Number: " . $service;
    }
} else {
    $response["error_message"] = "A valid CONTACT RECID could not be found in PCR360 based "
        . "on the incoming email address: " . $request["requestor"];
}

if (isset($response["error_message"])) {
    // log the error as a remark on the SO
    $payload["remarks"] = "A Service Desk Action could not be created on this Service Order "
        . "due to the following error: " . $response["error_message"];
}
$result = $this->call("saveServiceDesk", $payload);
$response["servicedesk_number"] = $result["data"];

Help Desk Portal - Email: help@pcr.com - Phone: 616.259.9242