Skip to main content

Notifications

Announcements

No record found.

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

  • saikrishna963 Profile Picture
    42 on at
    RE: I am trying to change the state code and status code from open , open to Completed and Closed

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

  • Suggested answer
    Bipin D365 Profile Picture
    28,977 Moderator on at
    RE: I am trying to change the state code and status code from open , open to Completed and Closed

    Hi,

    Optionset value looks good.

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

  • saikrishna963 Profile Picture
    42 on at
    RE: I am trying to change the state code and status code from open , open to Completed and Closed

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

  • Suggested answer
    Bipin D365 Profile Picture
    28,977 Moderator on at
    RE: I am trying to change the state code and status code from open , open to Completed and Closed

    Hi,

    Please share screenshot of your optionset field with values.

    Are you using custom entity?

  • saikrishna963 Profile Picture
    42 on at
    RE: I am trying to change the state code and status code from open , open to Completed and Closed

    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,977 Moderator on at
    RE: I am trying to change the state code and status code from open , open to Completed and Closed

    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

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,145 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,917 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans