web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Suggested Answer

I am trying to change the state code and status code from open , open to Completed and Closed

(0) ShareShare
ReportReport
Posted on by 42

I am trying to change the state code and status code from Open ,Open to Completed and Closed , I have written the code for that  below is the code, I have pasted the error, Please Help me

async function systemLogClose(executionContext)

{

      var formContext = executionContext.getFormContext();
      var statecode = formContext.getAttribute("statecode").getValue();
      var statusreason = formContext.getAttribute("statuscode").getValue();
      var fetchXml = "?fetchXml=<fetch>" +
            "<entity name='lgr_systemlog'>" +
            "<attribute name='activityid'/>" +
            "<attribute name='subject'/>" +
            "<attribute name='createdon'/>" +
            "<order attribute='subject' descending='false'/>" +
            "<filter type='and'>" +
            "<condition attribute='regardingobjectid' operator='not-null'/>" +
            "</filter>" +
            "</entity>" +
            "</fetch>";
      await Xrm.WebApi.online.retrieveMultipleRecords("lgr_systemlog", fetchXml).then(
            function success(result) {
                  if( statecode ==0 && statusreason == 1)   // 0 = Open and 1 = Open
                              {
                        formContext.getAttribute("statecode").setValue(1);   //  Completed
                        formContext.getAttribute("statuscode").setValue(2);   //  Closed
                               }
                  
            });

}

I am getting the below error

Exception Message: 2 is not a valid status code for state code lgr_systemlogState.Open on lgr_systemlog with Id 0e5cabbe-af6b-ed11-81ac-0022481b5c47.

ErrorCode: -2147187704
HexErrorCode: 0x80048408
ErrorDetails:
      ApiExceptionSourceKey: Plugin/Microsoft.Crm.ObjectModel.CustomActivityService
      ApiStepKey: 6190c079-2f6a-ed11-81ac-0022481b5f3c
      ApiDepthKey: 1
      ApiActivityIdKey: 559d3bc4-e840-4eb5-945e-03ad8b7cf809
      ApiPluginSolutionNameKey: System
      ApiStepSolutionNameKey: System
      ApiExceptionCategory: ClientError
      ApiExceptionMessageName: InvalidStateCodeStatusCode
      ApiExceptionHttpStatusCode: 400

Activity Id: 5da8d406-4e35-4204-abdb-d0181209fbac

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Please check optionset value of status code field by navigating to settings - customization - customize the system - Select your entity - fields - open status code field

    OR go to make.powerapps.com - Dataverse - Tables - Select your table - Fields - open Status field - verify optionset value

  • saikrishna963 Profile Picture
    42 on at

    Hi Bipin I have given correct values for everything as explained above 0pen - 0 (state code)

    open - 1 (status code) to Completed - 1(statecode) and Closed- 2 (statuscode)

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Please share screenshot of your optionset field with values.

    Are you using custom entity?

  • saikrishna963 Profile Picture
    42 on at

    IMG20221124102913.jpgHii bipin I am using custom entity IMG20221124104747.jpgIMG20221124161510.jpg

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Optionset value looks good.

    SystemLogClose function is registered on which event and on which entity?

  • saikrishna963 Profile Picture
    42 on at

    Hi Bipin My code is working fine now....I have removed this  "formContext.getAttribute("statuscode").setValue(2);" line and it worked now....Thankyou

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Suriyanarayanan V Profile Picture

Suriyanarayanan V 22

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 22 Super User 2026 Season 1

#3
Encore Business Solutions Profile Picture

Encore Business Sol... 14

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans