ASP page that changes workflow state

The following code is from a button on an ASP page that's called from a workflow rule associated with the communication entity. The button appears on the communication screen. When the user clicks the button, the communication is closed, the stage is changed, and the workflow state for the instance is updated.

The code shows how the workflow ID and the workflow instance are used to set the workflow state.

Copy
var strKeyID= "key6";
var Id = new String(Request.Querystring(strKeyID));
var intRecordId = 0;
if (Id.indexOf(",") > 0)
{
    var Idarr = Id.split(",");
    intRecordId = Idarr[0];
}
    else if (Id != "")
    {
        intRecordId = Id;
    }
    
//Retrieve Record
var myRecord = CRM.FindRecord("communication","comm_communicationid="+intRecordId);
myRecord.comm_status = 'Complete';
myRecord.SaveChanges();

////////////////////////////////////////
var myOppoRecord = CRM.FindRecord("opportunity","oppo_opportunityid="+CRM.GetContextInfo("opportunity","oppo_opportunityid"));
myOppoRecord.oppo_stage = 'Qualified';
myOppoRecord.SaveChanges();

//////////////////////////////////////////
// Please note that the wkin_currentstateid has to be checked with
// workflow definitions
var workflowinstanceRecord = CRM.FindRecord
("workflowinstance","wkin_instanceid="+
myOppoRecord.oppo_workflowid);
workflowinstanceRecord.wkin_currentstateid = 42;
workflowinstanceRecord.SaveChanges();

////////////////////////////////////////
Response.Redirect(CRM.URL(260));