Add more than one Secondary contact to Incident through CPM

Hi All,
I am trying to add more than one secondary contact to an Incident through Custom Process.
But, I am facing some error which is not causing the contact to get linked,
Below is the code
$i=0;
$res = RNCPHP\ROQL::queryObject( "SELECT Contact FROM Contact WHERE Emails.Address = '".$mail_addr."' AND Emails.AddressType = 0")->next();

while($contact = $res->next()){
$cid = $contact->ID;
}
if($cid != null){
echo "contact id: ".$cid;
$incident->OtherContacts = new RNCPHP\ContactArray();
$incident->OtherContacts[$i] = RNCPHP\Contact::fetch($cid);
$incident->save();
$i = $i + 1;
}

Please help in modifying this code.

Comments

With just looking at the code, one aspects looks problematic; I don't think you should be specifying an explicit index when adding the Contact to the OtherContact's array. With PHP , if you exclude an index, it will just push the item to the end of the array.

try this instead:

$incident->OtherContacts[] = RNCPHP\Contact::fetch($cid);

Zircon - This is a contributing Drupal Theme
Design by WeebPal.