This is some code from an asp page designed to be used in a cross entity workflow. The original page forms part of an Opportunity Workflow. But the actual code here was in an ASP page is called from a rule associated with the communication entity.
The button would appear on the communication screen and when pressed it would close the communication, then change the oppo_stage and update the workflow state for the instance.
If we are creating a new record in code then we can set the initial value of the workflow by using:
var myRecord = CRM.CreateRecord("TableName");
But this is not available for existing records so we must control the progress through the workflow ourself.
Below is the extract showing how the workflow id and the workflow instance as used to allow the setting of the workflow state.
var strKeyID= "key6";
var Id = new String(Request.Querystring(strKeyID));
var intRecordId = 0;
if (Id.indexOf(",") > 0)
var Idarr = Id.split(",");
intRecordId = Idarr;
else if (Id != "")
intRecordId = Id;
var myRecord = CRM.FindRecord("communication","comm_communicationid="+intRecordId);
myRecord.comm_status = 'Complete';
var myOppoRecord = CRM.FindRecord("opportunity","oppo_opportunityid="+CRM.GetContextInfo("opportunity","oppo_opportunityid"));
myOppoRecord.oppo_stage = 'Qualified';
//Please note that the wkin_currentstateid has to be checked with
var workflowinstanceRecord = CRM.FindRecord
workflowinstanceRecord.wkin_currentstateid = 42;