Quantcast
Channel: Discussion Forum > Connect Data Services
Viewing all articles
Browse latest Browse all 2504

Creating a Task from an incident and copying values (1 Comment)

$
0
0

Topic by Neil

Content

Hi,

I'm trying to create a CPM myself for the first time, and I'm running into difficulties.

My end-goal is to trigger the CPM from our incident Business Rules. The CPM should then create a task, and link it back to the incident. I'd then like to copy certain field values from the incident.

As a starting point, I've attempted to use the sample code from the documentation, but I'm still missing something.

Here is the full code from the CPM File:

<?php
/*
* CPMObjectEventHandler: Create_SMS_Task_CPM
* Package: RN
* Objects: Incident, Contact, Task
* Actions: Create,Update
* Version: 1.2
* Purpose: Create SMS Task when on saving incident
*/

// Specify a versioned namespace for the Connect PHP API
use RightNow\Connect\v1_2 as RNCPHP;

class Create_SMS_Task_CPM
    implements RNCPM\ObjectEventHandler
    
try{
    $new_task=new RNCPHP\Task();
    
    //Set assigned account
    $new_task->AssignedToAccount = RNCPHP\Account::fetch(9);
 
    //Set comment
    $new_task->Comment= "New task";
     
    //Set Completed time
    $new_task->CompletedTime=mktime(0,0,0,11,11,2018);
     
    //Set contact
    $new_task->Contact = RNCPHP\Contact::fetch(2039);
                        
    //Set due time
    $new_task->DueTime=mktime(0,0,0,14,11,2018);
     
    // Add FileAttachment
    $new_task->FileAttachments =new RNCPHP\FileAttachmentCommonArray();
    $fattach = new RNCPHP\FileAttachmentCommon();
    $fattach->ContentType = "text/text";
    $fp = $fattach->makeFile();
    fwrite($fp,"Making some notes in this text file for the Task".date("Y-m-d h:i:s"));
    fclose($fp);
    $fattach->FileName = "NewTextFile".date("Y-m-d_h_i_s").".txt";
    $fattach->Name = "New Text File ".date("Y-m-d h:i:s").".txt";
    $new_task->FileAttachments[] = $fattach;
    
    //Set Inherit
    $new_task->Inherit=new RNCPHP\InheritOptions();
    $new_task->Inherit->InheritContact=true;
    $new_task->Inherit->InheritOrganization=true;
    $new_task->Inherit->InheritStaffAssignment=true;
 
    //Set Name
    $new_task->Name="sample_task";
 
    //Add notes
    $new_task->Notes = new RNCPHP\NoteArray();
    $new_task->Notes[0] = new RNCPHP\Note();
    $new_task->Notes[0]->Channel = new RNCPHP\NamedIDLabel();
    $new_task->Notes[0]->Channel->LookupName = "Email";
    $new_task->Notes[0]->Text = "Sample task Notes 1";
    $new_task->Notes[1] = new RNCPHP\Note();
    $new_task->Notes[1]->Channel = new RNCPHP\NamedIDLabel();
    $new_task->Notes[1]->Channel->LookupName = "Phone";
    $new_task->Notes[1]->Text = "Sample task Notes 2";
    
    //Set Percent complete
    $new_task->PercentComplete=90;
     
    //Set Planned completion time
    $new_task->PlannedCompletionTime=mktime(0,0,0,5,11,2018);
 
    //Set Priority
    $new_task->Priority= new RNCPHP\NamedIDOptList();
    $new_task->Priority->ID=1;
     
    //Set Opportunity
    $new_task->SalesSettings=new RNCPHP\TaskSalesSettings();
    $new_task->SalesSettings->Opportunity= RNCPHP\Opportunity::fetch(9);
     
    //Add Answer and Incident
    $new_task->ServiceSettings=new RNCPHP\TaskServiceSettings();
    $new_task->ServiceSettings->Incident=RNCPHP\Incident::fetch(714057);
     
    //Set Start time
    $new_task->StartTime=mktime(0,0,0,10,10,2018);
    
    //Set the current status
    $new_task->StatusWithType = new RNCPHP\StatusWithType();
    $new_task->StatusWithType->Status->ID = 18;
     
    // Set Task template
    // $new_task->TaskTemplate=new RNCPHP\NamedIDLabel();
    // $new_task->TaskTemplate->ID=1;
 
    //Set Task type
    $new_task->TaskType=new RNCPHP\NamedIDOptList();
    $new_task->TaskType->ID=2;
 
    $new_task->save();
    echo "Task object has been created successfully with ID {$new_task->ID}";
}
 
catch (Exception $err ){
    echo $err->getMessage();
}

I'd be grateful if someone could give me some pointers please!

Code Block


Viewing all articles
Browse latest Browse all 2504

Trending Articles