Create a New Dataverse Record with Duplicate Detection Properties and Duplication Rules | PL-400 Exam | Microsoft Power Platform Developer

Create a New Dataverse Record with Duplicate Detection Properties and Duplication Rules

Question

You need to use the Organization service to create a new Dataverse record.

You want the duplication rules to be applied, and duplicate detection properties enabled for the account entity.

Your code should be able to catch if the new record has a duplicate.

What approach should you use for the record creation?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer: C

The Dataverse provides two web services to work with data using code: data service and Organization service.

You should use the Web API if you work with the Dataverse data service.

And for the Organization service, you use the .Net SDK API.

If you are using the Organization service for the Windows project, you need to use XRM Tooling assemblies.

When you work with Dataverse data using the Organization services, there are two coding data styles: the early-bound and late-bound.

The early-bound approach checks the types during the compilation time.

It uses the metadata for a class generation.

The late-bound checks the types only when the object is created, or actions rendered.

The late-bound style required to use the Entity class.

The late binding helps to work with the custom entities and attributes that were not available during the compile-time.

Here is a C# code example for early binding.

var account = new Account();
// setting the attributes values
account.Name = "CBImports";

//Create the account
Guid accountid = svc.Create(account);

And here is an example of late binding.

We are using Entity class with a logic name of the entity.

var account = new Entity("account");
// setting the attributes values
account ["name"] = "CBImports";

//Create the account
Guid accountid = svc.Create(account) ;

You also can create entities using the CreateRequest class.

Instead of using the IOrganizationService.Create method (in the above examples: Guid accountid = svc.Create(account)), you use IOrganizationService.Execute method to execute a request for the Target entity in the CreateRequest() call.

var request = new CreateRequest() { Target = account };
var response = (CreateResponse)svc.Execute( request);
Guid accountid = response. id;

The benefit of using the CreateRequest is that you can add a request parameter for revealing the record duplication and catching it as an error exception.

You can use any of the bindings for an account object.

var account = new Account();
account.Name = "CBimports";

var request = new CreateRequest() { Target = account };
request.Parameters.Add("SuppressDuplicateDetection", false);

try
{

svc.Execute( request);

}

catch (FaultException<O0rganizationServiceFault> ex)

{

All other options are incorrect.

For more information about using the Dataverse data operations using the Organization service, please visit the below URLs:

To create a new Dataverse record and apply duplicate detection rules, you can use the Organization service. The Organization service provides a set of APIs to interact with Dataverse data and metadata.

To enable duplicate detection and catch if the new record has a duplicate, you need to use the CreateRequest class. This class creates a new record and allows you to specify the properties of the new record.

To enable duplicate detection and catch if the new record has a duplicate, you should set the ReturnResponse property of the CreateRequest to true. This property ensures that the request returns the response that includes the status of the operation and any error messages.

When you use the CreateRequest, the duplication rules will be applied, and duplicate detection properties will be enabled automatically, based on the configuration of the entity.

You can use either early-bound or late-bound style to create the new record, depending on your preference. Early-bound style is preferred because it provides compile-time checking of types and properties, making it easier to catch errors before runtime. Late-bound style is useful when you need to work with dynamic entities or properties.

ExecuteTransactionRequest is not necessary for creating a single record, as it is used to group multiple requests into a single transaction. It is useful when you need to ensure that all requests in the transaction succeed or fail as a single unit.

In summary, the approach you should use for the record creation is to use the CreateRequest class and set the ReturnResponse property to true. You can use either early-bound or late-bound style depending on your preference. The ExecuteTransactionRequest is not necessary for creating a single record.