PL 400 : perform operations on data by using the Organization service API (Create a plug-in)

Data handling is an essential activity in all organizations. All organizations try to conduct CRUD operations with a variety of technologies. Undoubtedly, a plugin is a powerful tool for manipulating or extending the Microsoft Dataverse platform, but the organization service plays an important role for data operations.


Microsoft provides developers to take advantage of the web service at no extra cost. There are many web services that help the developer with particular custom logic or a custom interface for the programmatic implementation of the application, while controlling the back end business processes, security and auditing. Organization service is one of two web services we can use to work with data and table and column definition in Dataverse. The other is the Web API.

Microsoft Dataverse uses the Common Service-Oriented Architecture (SOA) concept for extensibility, which involves implementing a series of web services to provide extensibility support. By using these web services, we can integrate other applications and systems with Microsoft Dataverse and expand its capabilities. Web services are based on Simple Object Access Protocol (SOAP) messages. These protocols use XML, which provides usability through the Hypertext Transfer Protocol (HTTP) communication transport. In other words, it gives an easy way for applications and systems to communicate using standard protocols to interoperate and share functionalities.

The organization service is a .NET Framework SDK with .NET assemblies provided by Microsoft along with typed class generates for table classes. When we access data from a plugin, this service helps to access in the data. This service is instantiated and available to the plugin code without the need to authenticate.  To use this CRM service, we need to obtain an instance of IOganizationService which provides programmatic access to metadata and data for an organization.

IOganizationService has the following methods:

  • Create
  • Update
  • Delete
  • Execute
  • Retrieve
  • RetrieveMultiple
  • Associate 
  • Disassociate

Create:

The Create method is used to create new instances of an existing table, such as a new Account or Contact table. This method has only one implementation: It returns a globally unique identifier (GUID), which is the unique identifier of the new table to be created; it accepts one parameter of type table.

Update:

The Update method updates data related to an instance of an table. This method has only one implementation, and it doesn’t return a value.

Delete:

The Delete method deletes an existing instance or record of an table. This method doesn’t return any value and accepts two input parameters. The first parameter is a string containing the table type, and the second parameter is the GUID of the instance of the table you will delete.

Execute:

The Execute method executes business logic. It returns a Response object and accepts a parameter as the input of the Request type. You can use this method as a wildcard for all the other methods. This means you can create an account by using this method because the class called CreateRequest derives from Request and can be used as the input parameter; you receive a CreateResponse as the result. The same happens for UpdateRequest, UpdateResponse, RetrieveRequest, and RetrieveResponse.

Retrieve:

The Retrieve method gets an instance of an table object. To get more than one instance of an table, use the RetrieveMultiple method (explained in the next section). The Retrieve method returns a class type of table. The input parameters are the string of the table name, the GUID of the instance of the table, and a set of columns or fields you want to retrieve.

RetrieveMultiple:

The RetrieveMultiple method gets one or more instances of an table.

Associate:

Table rows are associated to each other using lookup columns on the related table row. The simplest way to associate two rows in a one-to-many relationship is to use an tableReference to set the value of a lookup column on the related row.

Disassociate:

The IOrganizationService.Disassociate method or the DisassociateRequest with the IOrganizationService.Execute method are just the reverse of the way that you associate table rows.


Early bound access to table columns

//Using the early-bound Account entity class
var account = new Account();
// set attribute values
// string primary name
account.Name = "Contoso";
// Boolean (Two option)
account.CreditOnHold = false;
// DateTime
account.LastOnHoldTime = new DateTime(2017, 1, 1);
// Double
account.Address1_Latitude = 47.642311;
account.Address1_Longitude = -122.136841;
// Int
account.NumberOfEmployees = 500;
// Money
account.Revenue = new Money(new decimal(5000000.00));
// Picklist (Option set)
account.AccountCategoryCode = new OptionSetValue(1); //Preferred customer

Late bound access to table columns

//Use Entity class with entity logical name
var account = new Entity("account");
// set attribute values
// string primary name

account["name"] = "Contoso";
// Boolean (Two option)
account["creditonhold"] = false;
// DateTime
account["lastonholdtime"] = new DateTime(2017, 1, 1);
// Double
account["address1_latitude"] = 47.642311;
account["address1_longitude"] = -122.136841;
// Int
account["numberofemployees"] = 500;
// Money
account["revenue"] = new Money(new decimal(5000000.00));
// Picklist (Option set)
account["accountcategorycode"] = new OptionSetValue(1); //Preferred customer



Comments

Popular posts from this blog

Powering Up Your Analytics: Exploring Power Query in Power BI

Power App Component Overview : Canvas App vs Model-Driven App

Exam PL-400: Microsoft Power Platform Developer