Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

CRM 2013 Plugin: Setting up new relationship on newly created Accounts

$
0
0

I'm creating a plugin for CRM 2013 (on-premise). My requirement is like this:

  1. When a custom entity "Contract" creates, fire the plugin.
  2. Contract has "1:1" relationship with the Quote entity.
  3. Quote has a 1:N relationship with custom entity 'Property'.
  4. For every properties that Quote has, create new Account records.
  5. Link the newly created Account records to the Contract. The relationship Contract to Account is 1 to N.

I got all working however keep getting problems with #5. For some reason the plugin throws an error that Account ID does not exist.

Here's my code:

foreach("**Property records found in Quote**"){var accountEntity =newEntity();
                    accountEntity =newEntity("account");if(record.Attributes.Contains("name")){
                        accountEntity["name"]= record.Attributes["propertyname"];}elsethrownewInvalidPluginExecutionException(OperationStatus.Failed,"New Property Name is needed.");

                    service.Create(accountEntity);var referenceCollection =newEntityReferenceCollection();var relatedEntity =newEntityReference{Id= record.Id,LogicalName= record.LogicalName};
                    referenceCollection.Add(relatedEntity);//The relationship schema name in CRM you are using to associate the entities. var relRelationship =newRelationship{SchemaName="new_new_contract_account"};

                    service.Associate("account",ContractId, relRelationship, referenceCollection);}

Viewing all articles
Browse latest Browse all 1000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>