locked
Update a ServiceActivity with State code 3 (Scheduled) to StateCode 1 and StatusCode 8. RRS feed

  • Question

  • I have been trying to update a ServiceActivity which has a stateCode 3(Scheduled) to statecode 1 and statuscode 8. 

    My code is as below. 

    Update updateEntry = new Update();
    Entity updateInfo = new Entity();
    Guid guid = new Guid();
    guid.setGuid(task.getExternalTaskReference());
    updateInfo.setId(guid);
    updateInfo.setLogicalName("serviceappointment");

    AttributeCollection updateCollection = new AttributeCollection();

    // StateCode: (0=Open,1=Completed,2=Cancelled,3=Scheduled)
    KeyValuePairOfstringanyType stateCode = new KeyValuePairOfstringanyType();
    stateCode.localKey="statecode";
    OptionSetValue stateCodeValue = new OptionSetValue();
    stateCodeValue.setValue(1); // 1 is Completed
    stateCode.setValue(stateCodeValue);

    // StatusCode: (1=Requested,2=Cancelled,3=Pending,4=Reserved,6=InProgress,7=Arrived,8=Completed,9=Cancelled,10=NoShow)
    KeyValuePairOfstringanyType statusCode = new KeyValuePairOfstringanyType();
    statusCode.localKey = "statuscode";
    OptionSetValue statusCodeValue = new OptionSetValue();
    statusCodeValue.setValue(8); // was Reserved (4) -> 8 is Completed
    statusCode.setValue(statusCodeValue);

    //updateCollection.addKeyValuePairOfstringanyType(category);
    updateCollection.addKeyValuePairOfstringanyType(stateCode);
    updateCollection.addKeyValuePairOfstringanyType(statusCode);
    updateInfo.setAttributes(updateCollection);
    updateEntry.setEntity(updateInfo);

    System.out.println("Updating service activity: " + guid.getGuid());

    UpdateResponse updateResponse = serviceStub.update(updateEntry);

    The error I get is 

    8 is not a valid status code for state code ServiceAppointmentState.Scheduled on serviceappointment with Id 7b12f93f-e0a6-e411-80e4-c4346bad02e8.

    Please can you help me close this service activity.

    Wednesday, January 28, 2015 1:04 PM