DYNAMICS 365 UPDATE RECORD STATUS AFTER SETSTATEREQUEST DEPRECATED

In a previous post, we saw how to change record owner in Dynamics 365 using C# after the AssignRequest message is deprecated.

In addition, 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);
    }

    Update record status 1

  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);
    }

    Update record status 2

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


Hope This Helps!

Comments

Popular posts from this blog

DYNAMICS 365 HOW TO HIDE RECENT RECORDS FOR LOOKUP FIELD IN UCI

SEARCH BY GUID IN DYNAMICS 365

SAVE FORM IN DYNAMICS 365 JAVASCRIPT