Skip to content

Ability to associate Activity Parties #16

Open
@shaunjc

Description

@shaunjc

Native support for Activity parties does not appear to be a core part of the toolkit functionality. The serialization helper seems to strip these fields as they do not show in the returned metadata with the current implementation.

As an example, attempting to create a campaignresponse with a matching customer does not work like the standard way to update and associate records.

$contact_ref = new \AlexaCRM\Xrm\EntityReference( 'contact', $contactid );

// $campaignresponse['customer'] is stripped out during $serializer->serializeEntity( $campaignresponse ); A 400 Bad Request error would be thrown otherwise.
$campaignresponse['customer'] = $contact_ref;

// A different 400 Bad Request error is thrown for attempting to associate using this action.
$client()->Associate(
    'campaignresponse',
    $campaignresponse->Id,
    new \AlexaCRM\Xrm\Relationship( 'contact_campaigncesponses' ),
    [ $contact_ref ]
);

// Same for the reverse association - a similar error will be thrown.
$client()->Associate(
    'contact',
    $contactId,
    new \AlexaCRM\Xrm\Relationship( 'contact_campaigncesponses' ),
    [ new \AlexaCRM\Xrm\EntityReference( 'campaignresponse', $campaignresponse->Id )]
);

// It is possible to set this by serializing the data, adjusting the payload and using the OData Client.
$serializer = new \AlexaCRM\WebAPI\SerializationHelper( $client->getClient() );
// Creating the ActivityParty as an Entity helps with serialization.
$activityparty = new \AlexaCRM\Xrm\Entity( 'activityparty' );
$activityparty['partyid'] = $contact_ref;
$activityparty['participationtypemask'] = 11;
// Activity Party and campaign response are serialized and attached to each other.
$translatedData = $serializer->serializeEntity( $campaignresponse );
$translatedData['campaignresponse_activity_parties'] = array( $serializer->serializeEntity( $activityparty ) );
// Using the OData\Client gets around serialized data being lost.
$client->getClient()->update( $client->getClient()->getMetadata()->getEntitySetName( 'campaignresponse' ), $translatedData );

A new class for Activity Party entity types which encode themselves appropriately and possibly match the correct parts of the metadata, would help simplify the process of linking data.

// Potential new class
class ActivityParty implements \ArrayAccess {
    public $Entities = [];
    public function __construct( $entityReference, $type ) {
    }
}
// Possible example usage
$activityparty = new ActivityParty( $contact_ref, ActivityParty::TYPE_CUSTOMER );
$campaignresponse['campaignresponse_activity_parties'] = $activityparty;

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions