< Back

Add-CrmMultiRecordAssociation

Sat Jan 18, 2020 3:57 pm

NAME Add-CrmMultiRecordAssociation



SYNOPSIS

Associates multiple records to single record for N:N relationship.





SYNTAX

Add-CrmMultiRecordAssociation [-conn <CrmServiceClient>] [-CrmRecord1] <PSObject> [-CrmRecord2s] <PSObject[]>

[-RelationshipName] <String> [[-IsReflexiveRelationship] <Boolean>] [<CommonParameters>]



Add-CrmMultiRecordAssociation [-conn <CrmServiceClient>] [-EntityLogicalName1] <String> [-Id1] <Guid>

[-EntityLogicalName2] <String> [-Id2s] <Guid[]> [-RelationshipName] <String> [[-IsReflexiveRelationship]

<Boolean>] [<CommonParameters>]





DESCRIPTION

The Add-CrmMultiRecordAssociation cmdlet lets you associate multiple records to single record for N:N relationship

by specifying relatioship logical name.

Use @('<object>','<object>') syntax to specify multiple ids or records.

if the relationship is self-referencing, specify $True for -IsReflexiveRelationship Parameter.



There are two ways to specify records.



1. Pass EntityLogicalName and record's Id for both records.

2. Get record object(s) by using Get-CrmRecord/Get-CrmRecords cmdlets, and pass them.



You can specify relationship logical name for the association.





PARAMETERS

-conn <CrmServiceClient>

A connection to your CRM organization. Use $conn = Get-CrmConnection <Parameters> to generate it.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-CrmRecord1 <PSObject>

A first record object which is obtained via Get-CrmRecord/Get-CrmRecords. When you pass CrmRecord, then you

don't use EntityLogicalName/Id.



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-CrmRecord2s <PSObject[]>

An array of records object which are obtained via Get-CrmRecord/Get-CrmRecords. When you pass CrmRecord, then

you don't use EntityLogicalName/Id.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-RelationshipName <String>

A N:N relationship logical name.



Required? true

Position? 5

Default value

Accept pipeline input? false

Accept wildcard characters? false



-IsReflexiveRelationship [<Boolean>]

Specify $True if the N:N relationship is self-referencing.



Required? false

Position? 6

Default value

Accept pipeline input? false

Accept wildcard characters? false



-EntityLogicalName1 <String>

A logicalname for first Entity. i.e.)account, contact, lead, etc..



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Id1 <Guid>

An Id (guid) of first record



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-EntityLogicalName2 <String>

A logicalname for second Entity. i.e.)account, contact, lead, etc..



Required? true

Position? 3

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Id2s <Guid[]>

An array of Ids (guid) of second records. Specify by using

@('66005a70-6317-e511-80da-c4346bc43d94','62005a70-6317-e511-80da-c4346bc43d94') syntax.



Required? true

Position? 4

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS









OUTPUTS









NOTES









-------------------------- Example 1 --------------------------



Add-CrmMultiRecordAssociation -conn $conn -EntityLogicalName1 account -Id1 00005a70-6317-e511-80da-c4346bc43d94

-EntityLogicalName2 contact -Id2s @('66005a70-6317-e511-80da-c4346bc43d94','62005a70-6317-e511-80da-c4346bc43d94')

-RelationshipName new_accounts_contacts



This example associates an account and two contact records through new_accounts_contacts custom N:N relationship.







-------------------------- Example 2 --------------------------



Add-CrmMultiRecordAssociation account 00005a70-6317-e511-80da-c4346bc43d94 contact

@('66005a70-6317-e511-80da-c4346bc43d94','62005a70-6317-e511-80da-c4346bc43d94') new_accounts_contacts



This example associates an account and two contact records through new_accounts_contacts custom N:N relationship

by omitting parameters names.

When omitting parameter names, you do not provide $conn, cmdlets automatically finds it.







-------------------------- Example 3 --------------------------



PS C:\\>$account = Get-CrmRecord account 00005a70-6317-e511-80da-c4346bc43d94 name



PS C:\\>$fetch = @"

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" no-lock="true">

<entity name="contact">

<attribute name="fullname" />

<filter type="and">

<condition attribute="lastname" operator="like" value="%sample%" />

</filter>

</entity>

</fetch>

"@



PS C:\\>$contacts = Get-CrmRecordsByFetch $fetch



PS C:\\>Add-CrmMultiRecordAssociation $account $contacts.CrmRecords new_accounts_contacts



This example retrieves contacts by using FetchXML and stores to a variable, then retrieves and store an account

record to another variable.

Then passes those variables Add-CrmMultiRecordAssociation.









RELATED LINKS