Sam's Microsoft Dynamics 365 Blog

Wednesday 5 September 2018

Insert and Get Value in MultiSelect Option Set Using C#

A new enhancement in Dynamics CRM is Multiselect Option set. We Insert Value using below code in Multiselect Option set.


Syntax:-  OptionSetValueCollection OPcollection = new OptionSetValueCollection() { new OptionSetValue(<value1>), new OptionSetValue(<value2>)};

Example:-
OptionSetValueCollection OPcollection = new OptionSetValueCollection() { new OptionSetValue(364760001), new OptionSetValue(364760002)};

Entity _account = new Entity("account");
_account.Attributes["name"] = "multiselect optionset test test";
_account.Attributes["new_myhobby"] = OPcollection;
var guiddata = _orgService.Create(_account);



We can Get Value using below code in Multiselect Option set.



Syntax:-  
OptionSetValueCollection OptionCollection = (OptionSetValueCollection)entity.Attributes["<FieldName>"];

foreach (var optionSetValue in OptionCollection)
  {
          OptionSetValue opVal = (OptionSetValue)optionSetValue;
  }

Example:-

OptionSetValueCollection OptionCollection = (OptionSetValueCollection)entity.Attributes["new_myhobby"];
foreach (var optionSetValue in OptionCollection)
   {
          OptionSetValue opVal = (OptionSetValue)optionSetValue;
   }


Get and Set value in MultiSelect Option Set Using JavaScript


A new enhancement in Dynamics CRM is Multiselect Option set. We can Get and Set Value using below code in the Multiselect Option set using Javascript:-

Get the value of a Multiselect Option Set

Get Value:-
     Syntax:-   Xrm.Page.getAttribute('FieldName').getValue();

     Example:-  Xrm.Page.getAttribute('new_myhobby').getValue();

Set the value of a Multiselect Option Set

Set Value:-
     Syntax:-   Xrm.Page.getAttribute('FieldName').setValue([<Value1>,<Value2>);

     Example:- Xrm.Page.getAttribute('new_myhobby').setValue([360002,3660001]);

What's new in Dynamics 365 Version 9.0

1. Unified Client Interface
2. New Activity Timeline
3. LinkedIn Sales Navigator
4. Virtual Entities
5. Web Client Refresh
6. Customer Service Hub
7. Multi-Select Option Sets
8. Activity Logging
9. Business Process Flow Enhancements
10. Customer Insights


1. Unified Client Interface
There is a new interface – a Unified Interface which takes a mobile first approach. This is a huge face lift to the application and is more accessible than before.
We are becoming a blended, Dynamics 365 family and this new Office 365 portal-esque client reflects that.  Clean navigation, crisp layout of fields, grids, and former white-space.  We’ll also see a responsive UI for other platforms and devices — including Mobile and Tablets, Customer Service Hub, and Business Edition apps.



2. New Activity Timeline
An important component within the rollout of the Unified User Interface is a new timeline control that will replace the social pane in the legacy web client.Currently, this control requires users to click between tabs for Activities, Notes and Posts and it lacks a chronological view.Similar to the display previously seen in the Interactive Service Hub, Microsoft is combining these items into a single Activity Timeline that tracks the complete record history.


3. LinkedIn Sales Navigator


Following Microsoft’s acquisition of LinkedIn, more integration capabilities are being released.
A new connector for LinkedIn Lead Gen Forms automatically syncs campaigns and leads with Dynamics 365, with configurable matching rules
To aid social selling, new LinkedIn Sales Navigator embedded widgets for Dynamics 365 include account connections promoting the best contacts to connect with, recommended potential leads, account news, mutual connections to facilitate new introductions and summary detail from LinkedIn


 Selectively sync inMail and regular messages to Dynamics as specialized LinkedIn activities.

Automatically sync Dynamics 365 account and contacts, as well as Dynamics leads that are synchronized as suggested leads






4. Virtual Entities
Virtual Entities are similar to our traditional entities.  However, external data is read at run-time and not stored in the Dynamics 365 database.  This is a great new feature for heavy, custom integrations.  As you create an organization-owned entity, check a metadata box to indicate that it is virtual.
Virtual entities look to be integrated to Grids, Find, Forms, Lookups and Subgrids and appear to support being pulled in from ODATA and DOCDB.



CRUD Operation Using Xrm.WebApi



In Dynamics 365 One of the important enhancement is Xrm.WebApi. Dynamics 365 v9.0 which will help to make developers life simple. We can perform below operations in Xrm.WebApi.

Method
Description
createRecord
Creates an entity record.
deleteRecord
Deletes an entity record.
retrieveRecord
Retrieves an entity record.
retrieveMultipleRecords
Retrieves a collection of entity records.
updateRecord
Updates an entity record.
isAvailableOffline
Returns a Boolean value indicating whether an entity is present in user’s profile and is currently available for use in offline mode.
execute
Execute a single action, function, or CRUD operation.
executeMultiple
Execute a collection of action, function, or CRUD operations.



Note: Supports Dynamics 365 (online), version 9.x

Create

Create a record in an entity.

Syntax:-
Xrm.WebApi.createRecord(entityLogicalName, data).then(successCallback, errorCallback);

Example:-
// define the data to create new account
var _accountData =
    {
        "name": "Sam test",
        "creditonhold": false,
        "address1_latitude": 47.639583,
        "description": "Example of WebApi",
        "revenue": 1000000,
        "accountcategorycode": 1
    }

// create account record
Xrm.WebApi.createRecord("account", accountData).then(
    function success(result) {
        console.log("Account created with ID: " + result.id);
        // perform operations on record creation
    },
    function (error) {
        console.log(error.message);
        // handle error conditions
    }
);
Response:-




Retrieve

Retrieve a single record of an entity.

Syntax:-
Xrm.WebApi.retrieveRecord(entityLogicalName, id, options).then(successCallback, errorCallback);

Example:-
// retrieve a single record
Xrm.WebApi.retrieveRecord("account", "4263f467-f9af-e811-a95c-000d3a3780dd", "?$select=name,revenue").then(
    function success(result) {
        console.log(`Retrieved values: Name: ${result.name}, Revenue: ${result.revenue}`);
        // perform operations on record retrieval
    },
    function (error) {
        console.log(error.message);
        // handle error conditions
    }
);

Response:-




Retrieve Multiple Records

Retrieve a collection of records from an entity.

Syntax:-
Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize).then(successCallback, errorCallback);

Example:-
// retrieve multiple records
Xrm.WebApi.retrieveMultipleRecords("account", "?$select=name&$top=3").then(
    function success(result) {
        for (var i = 0; i < result.entities.length; i++) {
            console.log(result.entities[i]);
        }                   
        // perform additional operations on retrieved records
    },
    function (error) {
        console.log(error.message);
        // handle error conditions
    }
);

Response:-





Update Records

Update a record of an entity.

Syntax:-
Xrm.WebApi.updateRecord(entityLogicalName, id, data).then(successCallback, errorCallback);

Example:-
// define the data to update a record
var _accountUpdateData =
    {
        "name": "Updated Sam test Account ",
        "creditonhold": true,
        "address1_latitude": 47.639583,
        "description": "This is the updated description of the sample",
        "revenue": 6000000,
        "accountcategorycode": 2
    }
// update the record
Xrm.WebApi.updateRecord("account", "4263f467-f9af-e811-a95c-000d3a3780dd", _accountUpdateData).then(
    function success(result) {
        console.log("Account updated");
        // perform operations on record update
    },
    function (error) {
        console.log(error.message);
        // handle error conditions
    }
);

Response:-




Delete Records

Delete a record of an entity.

Syntax:-
Xrm.WebApi. deleteRecord(entityLogicalName, id).then(successCallback, errorCallback);

Example:-
// delete an account record
Xrm.WebApi.deleteRecord("account", "4263f467-f9af-e811-a95c-000d3a3780dd").then(
    function success(result) {
        console.log("Account deleted");
        // perform operations on record deletion
    },
    function (error) {
        console.log(error.message);
        // handle error conditions
    }
);

Response:-




Web Resource vs PCF vs Canvas App - which of the one is used?

While started working on specific Business Requirements related to custom layout, there is a always common question that "where to star...