Here we will be cloning the below contact record –
For it, we can make use Clone method of EntityExtensions class
If we run the below code, we will get the “Cannot insert duplicate key” exception.
Because we need to set the ID for the newly cloned record to either empty or a new GUID.
Also, we need to remove the contactid attribute or entity’s id field else we will get the below exception – “Entity Id must be the same as the value set in property bag“
Also if we are retrieving all the attributes we need to make sure we remove those attribute which can cause below unique constraint errors.
Sql error: The operation attempted to insert a duplicate value for an attribute with a unique constraint. CRM ErrorCode: -2147012606 Sql ErrorCode: -2146232060 Sql Number: 2627
In case of contact, we had to remove the address id attributes, to get the record cloned.
Now let us clone the same contact record with its related leads.
- Here first we need to retrieve contact along with its associated lead record.
- Then remove the id attribute that could duplicate issues in the child lead records also.
Please refer the helpful posts –
Hope it helps..
// related lead records of contact
QueryExpression query = new QueryExpression("lead");
query.ColumnSet = new ColumnSet(true);
// contact and lead - 1 - n relationship
Relationship relationship = new Relationship("lead_parent_contact");
relationship.PrimaryEntityRole = EntityRole.Referenced;
RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection();
RetrieveRequest request = new RetrieveRequest();
request.RelatedEntitiesQuery = relatedEntity;
request.ColumnSet = new ColumnSet(true);
request.Target = new EntityReference("contact", new Guid("ca0aa844-57c6-ec11-a7b6-00224826af1e"));
RetrieveResponse response = (RetrieveResponse)svc.Execute(request);
var contactToBeCloned = response.Entity;
var clonedContact = contactToBeCloned.Clone(true);
// remove attribute that can cause error from main entity
clonedContact.Id = Guid.NewGuid();
// remove attribute that can cause error from child / related entities
foreach (var relatedEntities in clonedContact.RelatedEntities)
foreach(var leadEntity in relatedEntities.Value.Entities)
leadEntity.Id = Guid.NewGuid();
Filter rows and Trigger Conditions can be used to specify the condition on which the trigger should fire. This makes sure that we do not exceed flow execution limits.
Power Automate Licensing – Power Platform Requests
Power Automate Limits and Configuration
In the case of our Dataverse trigger “When a row is added, modified or deleted” we can make use of either Filter rows or Trigger Conditions, as we have both options available.
We’d be using Trigger Conditions for those triggers where we do not have additional property to specify the filter condition.
E.g. we want the flow to run only on a specific file in a library or based on the extension of the file as nicely explained here
Now out of curiosity, we tried specifying both Filter rows and Trigger conditions to see how it behaves.
Here for the same trigger we have specified Filter Rows as below
address1_city eq ‘Ahmedabad’
And Trigger Conditions as below
During our test, we observed that the trigger is firing only when both the conditions or expressions, specified in Filter Rows as well as Trigger Conditions are true.
So basically it will only fire for those rows or records having Company as MS and City equal to Ahmedabad.
It will not fire if either of Filter Rows or Trigger Conditions expression evaluate to be false.
Hope it helps..
Recently while using Delay until property of the trigger, in one of the flows, we got the below error
“Unable to process template language expressions for trigger ‘When_a_row_is_added,_modified_or_deleted’ at line ‘1’ and column ‘16344’: ‘In the template language function ‘convertToUtc’, the value provided for the time zone id ‘Gulf Standard Time’ was not valid. ‘.”
Usage of Delay until is nicely explained here by Debajit –
Delay until = convertToUtc(‘2022-05-16T17:22:00′,’Gulf Standard Time’)
It turns out that Gulf Standard Time is not a valid time zone id.
Changing it to Arabian Standard Time resolved the issue for us.
convertToUtc(‘2022-05-16T19:22:00′,’Arabian Standard Time’)
Also check – https://nishantrana.me/2022/01/19/how-to-use-do-until-and-delay-in-power-automate/
Hope it helps..
Recently in one of our projects, where we were using the auto number attribute (with sequential numbers), we realized that it gets incremented even in case of an exception thrown during Pre Stage of the Plugin Execution. We were assuming the number gets incremented only after the record gets created i.e. on post-stage.
But as the documentation mentions, the number gets pre-selected as soon as the record is started.
Let us see it in action also –
Here we have the lead record created with My Autonumber as the auto number column with seed as 1000
The auto number field has a value of 1009 currently.
Now let us register a plugin on the Pre-Create stage that throws the exception.
Let us try creating a new lead record, which as expected will throw the exception.
Let us try saving the record 3 times more, triggering the record creation as well as the plugin along with the exception.
Now let us disable the plugin step and save/create the record.
As expected the record gets created, and the auto number field has a value of 1014.
The same behavior was observed in case of Pre-Validation stage.
Hope it helps..
Recently while creating a Dynamics 365 Trial, https://dynamics.microsoft.com/en-us/dynamics-365-free-trial/, we were getting the below error, during the verification step
“Sorry, we need additional information to verify your identity. Please Contact Support”
This error could be related to the same phone number being used multiple times to create the Dynamics 365 trial or could be related browser cache.
Before trying with a new phone number, we should first try creating a trial in the In-Private mode (or clear cache in the browser).
In our case, the In-Private mode worked as shown below, and we were able to create the trial.
Hope it helps..