Monday, 11 April 2022

DYNAMICS 365 UPDATE RECORD STATUS AFTER SETSTATEREQUEST DEPRECATED

 

Previously, when we wanted to update the status of a record, we had to use the SetStateRequest message to set it.

However, as you all know, since the message SetStateRequest is deprecated, you can now use the Update request in order to set the status of a record without doing another specific call.

In this post, we will see the function on how to change record status in Dynamics 365 using C#.

  1. Below is the deprecated SetStateRequest message used to set the status of a record

    public void SetStateRequest(Account account)
    {
    SetStateRequest setStateRequest = new SetStateRequest
    {
    EntityMoniker = new EntityReference(Account.EntityLogicalName, account.Id),
    State = new OptionSetValue(0),
    Status = new OptionSetValue(1)
    };
    AdminService.Execute(setStateRequest);
    }

    image

  2. Currently, to set the status of a record you can use the Update message as below

    public void UpdateAccountStatus(Account account)
    {
    Account accountToUpdate = new Account
    {
    Id = account.Id,
    Name = "Account Status set using Update message",
    StateCode = AccountState.Active,
    StatusCode = new OptionSetValue((int)Account_StatusCode.Active),
    };
    AdminService.Update(accountToUpdate);
    }

    image

Bonus Tip:
Don't forget to check and change the use of the SetStateRequest in case you are migrating your environment.

No comments:

Post a Comment

Power Apps Drag & Drop Kanban code sample

  Introduction: The Kanban Board App Developers at a software company use the Kanban board to show their progress on development tasks and b...