Forum Stats

  • 3,759,917 Users
  • 2,251,615 Discussions
  • 7,870,869 Comments

Discussions

How to remove/update the Secondary Contact in an incident using CPM?

Vaishali Rajput
Vaishali Rajput Member Posts: 1 Green Ribbon

Hi,

I am trying to remove the secondary contacts from an incident for a certain contact once that contact's primary email id is changed, I am able to successfully update the email if of a contact, but somehow facing difficulty in removing the secondary contact from all the incidents of that particular contact.

For example -

I have a contact with email id [email protected] and it has 3 incidents,

then I want that whenever the primary email for contact changes from [email protected] to [email protected], all the incidents of that contact, should remove the secondary contact from them.

Currently, I am using this,

private static function multipleIncidents($contact_update) {

try {

foreach ($contact_update as $eachContactIncidentID) {

$contact_incident_update = RNCPHP\Contact::fetch($eachContactIncidentID);

//IF you want to fetch Primary mail

if (isset($contact_incident_update -> Emails[0])) {

//$Contact_Email = $contact_incident_update -> Emails[0] -> Address;

$Contact_Email = $contact_incident_update -> Emails[0];

}

$incident_contacts = RNCPHP\ROQL::query("SELECT PrimaryContactIncidents.ID FROM Contact WHERE Contact.CustomFields.c.source_system=".$source_system." and Contact.Emails.EmailList.Address in (" .$Contact_Email. ") LIMIT 100") -> next();

while ($eachConIncID = $incident_contacts -> next()) {

if ($eachConIncID['ID'] != null) {

$IncObject = RNCPHP\Incident::fetch($eachConIncID['ID']);

//Removing secondary contacts

$f_count = count($IncObject -> OtherContacts);

if($f_count > 0 ){

for($f = ($f_count-1); $f >=0 ; $f--) {

$IncObject -> OtherContacts-> offsetUnset($f);

}

}

echo 'Updating Incident id : ' . $IncObject -> ID . "\n";

$IncObject -> save(RNCPHP\RNObject::SuppressAll);

}

}

}

Please suggest how to resolve this query.

Thanks

Answers