Process making me cross-eyed

  • 11 November 2008
  • 3 replies
  • 0 views

Badge +3

We have a process that utilizes a smart object to store its data.  The process instance is related to the smart object via a process-wide datafield called "Proc_SOID".  The Smart Object is related back to the process instance via a property called "K2ProcID".  The smart object is added in the process workflow as a reference with the method set to the use Load method.   The input parameter is the autonumber of the smart object ("SOID") and is bound to the datafield ("Proc_SOID").  Both the process and the smart object are created in the code-behind of a asp.net page.  The problem is that when I create them, the smart object property "K2ProcID" will not hold the value I feed it.  It doens't throw an error - it just doens't update.  Here is a sample of the code...

 

public void GoK2()
    {
        try
        {
            // create an instance of the k2 process
            string K2processName = "ProcessProcessInstance";
            Connection cnnProcess = new Connection();
            cnnProcess.Open(ConfigurationManager.AppSettings["k2server"], ConfigurationManager.AppSettings["K2_StartWorkflow"]);
            ProcessInstance K2procInst = cnnProcess.CreateProcessInstance(K2processName);

            // start the process
            cnnProcess.StartProcessInstance(K2procInst, false);

            // create an instance of the smart object
            SourceCode.SmartObjects.Client.SmartObjectClientServer cnnSmartObject = new SmartObjectClientServer();
            cnnSmartObject.CreateConnection();
            cnnSmartObject.Connection.Open(ConfigurationManager.AppSettings["K2_CreateSmartObject"]);
            SmartObject smartObject = cnnSmartObject.GetSmartObject("ProcessSmartObject");
            smartObject.MethodToExecute = "Create";

            // set the smart object fields
            smartObject.Properties["cct_mem_name"].Value = lblMemberName2.Text;
            smartObject.Properties["cct_mem_email"].Value = txtEmail.Text;
            cnnSmartObject.ExecuteScalar(smartObject);

            // link the process instance to the smart object
            K2procInst.DataFields["Proc_SOID"].Value = smartObject.Properties["SOID"].Value;
            K2ProcID = K2procInst.ID.ToString();
            K2procInst.Update();
            cnnProcess.Close();

            // link the smart object to the process instance
            smartObject.Properties["K2ProcID"].Value = K2ProcID;
            cnnSmartObject.ExecuteScalar(smartObject);
            cnnSmartObject.Connection.Close();

        }
        catch (Exception ex)
        {
            // write error to console
            Response.Write("Error: " + ex.Message);
        }
       
    }

  

any thoguhts?  Thanks!


3 replies

Badge +2

Have you tried setting the procedure to call equal to "Save" prior to making the second call to executeScalar.

Badge +9

Are you sure that K2ProcID even has a value in your ASP.NET code?  Try stepping through with the VS debugger and see if there is a valid Proc Inst ID.

Generally when I do similar operations to this I make sure I invoke the process Synchronously tells K2 to start the instance and block return to the calling application until the process hits a stop point (e.g. something like a client event).  The API will then update my local ProcessInstance object with some information (like perhaps procinstid).  I see you are invoking this asynchronously which just tells K2 to start the process instance and immediately return to the calling code without regard to anything happening on the K2 server.

The specific line of code i'm referring to is:

             cnnProcess.StartProcessInstance(K2procInst, false);

I'd recommend to try switching the false to true:

             cnnProcess.StartProcessInstance(K2procInst, true);

and then try again and see if you have any better results.

HTH.

 

Badge +3

THAT DID IT!

            // create an instance of the k2 process
            string K2processName = "ProcessProcessInstance";
            Connection cnnProcess = new Connection();
            cnnProcess.Open(ConfigurationManager.AppSettings["k2server"],         ConfigurationManager.AppSettings["K2_StartWorkflow"]);
            ProcessInstance K2procInst = cnnProcess.CreateProcessInstance(K2processName);

            // start the process
            cnnProcess.StartProcessInstance(K2procInst, true);

            // create an instance of the smart object
            SourceCode.SmartObjects.Client.SmartObjectClientServer cnnSmartObject = new         SmartObjectClientServer();
            cnnSmartObject.CreateConnection();
            cnnSmartObject.Connection.Open(ConfigurationManager.AppSettings["K2_CreateSmartObject"]);
            SmartObject smartObject = cnnSmartObject.GetSmartObject("ProcessSmartObject");
            smartObject.MethodToExecute = "Create";

            // set the smart object fields
            smartObject.Properties["cct_mem_name"].Value = lblMemberName2.Text;
            smartObject.Properties["cct_mem_email"].Value = txtEmail.Text;
            cnnSmartObject.ExecuteScalar(smartObject);
            smartObject.MethodToExecute = "Save";

            // link the process instance to the smart object
            K2procInst.DataFields["Proc_SOID"].Value = smartObject.Properties["SOID"].Value;
            K2ProcID = K2procInst.ID.ToString();
            K2procInst.Update();
            cnnProcess.Close();

            // link the smart object to the process instance
            smartObject.Properties["K2ProcID"].Value = K2ProcID;
            cnnSmartObject.ExecuteScalar(smartObject);
            cnnSmartObject.Connection.Close();

 THANK YOU
ediaz009
and
Bob!

Reply