HPSM - Closing a changes has an unexpected result.

Hello, 

Im working with HPSM v9.32 and are trying to create a C# application which can Close a Change. 

Currently we have serveral application able create changes, incidents and so on. but when im implementing the Close Change it has a strange outcome.

What happens is that the case im trying to close gets closed, but somehow cloned and recreated with a new ChangeNumber. (The old one is sucessfully set to Closed however). 

Im not sure what can be causing this, so here is my code and im hoping anyone here can shead some light over this issue.

Here is the CloseChange method with some supporting functions. 

 

     public RequestStatus CloseChange(string caseNumber, string closingComment)
        {
            try
            {
                using (var client = new ChangeManagementClient())
                {
                    var model = new ChangeModelType();
                    var keys = new ChangeKeysType()
                    {
                        ChangeNumber = GetStringTypeVal(caseNumber),
                        
                        
                    };

                    SetCredentials(client);

                    model.keys = keys;
                    model.instance = CreateCloseInstance(closingComment, caseNumber);

                    var request = new CloseChangeRequest
                    {
                        model = model,
                        attachmentData = true,
                        attachmentInfo = true,
                        attachmentDataSpecified = true
                    };

    
                    var response = client.CloseChange(request);

                    if (response.status == StatusType.FAILURE)
                    {
                        return RequestHelper.CreateError(response.message);
                    }
                    var caseId = response.messages[0].Value;
                    return RequestHelper.CreateSuccess(CaseIdHelper(caseId));
                }
            }
            catch (Exception e)
            {
                return RequestHelper.CreateError(e.ToString());
            }
        }

private ChangeInstanceType CreateCloseInstance(string closeComment, string caseNumber)
{
var change = new ChangeInstanceType();

change.header = new ChangeInstanceTypeHeader
{
ChangeNumber = GetStringTypeVal(caseNumber),
CloseTime = GetDateTypeVal(DateTime.Now),
CurrentPhase = GetStringTypeVal("Inform & Closure:887")
};
change.ClosureComments = new ChangeInstanceTypeClosureComments()
{
ClosureComments = GetStringArrayTypeVal(closeComment)
};

return change;
}

private static StringType GetStringTypeVal(string value)
{
return new StringType { Value = value };
}

private static StringType[] GetStringArrayTypeVal(string value)
{
var temp = new StringType[1];
temp[0] = GetStringTypeVal(value);
return temp;
}