Access to ProcessContext instance from server code.

Can anyone please tell me how I can reference the ProcessContext instance from within server script code?  The instance can be accessed from the expression builder, as shown here:

 

12-4-2013 12-49-01 PM.png

 

But when I try to use it in a script, it's actually referring to the ProcessContext class because it's only showing its static members:

 

12-4-2013 12-51-46 PM.png

Tagged:

Comments

  • You need to pass an instance of ProcessContext class to your server script method:

     

    public class ServerScript1
      {
        [Promote(PromotionTargets.VisualToolbox)]
        [Category("UserCategory")]
        public static string SampleProcessContext(ProcessContext context)
        {
            return context.FolderSubject;
        }
      }
    

    In the Designer environment, the instance is called ProcessContext (same as class), so you will pass it this way:

    string s1 = ServerScript1.SampleProcessContext(ProcessContext);
    

     

     

     

     

  • Except, I'm calling my server script from a visual script activity in a start action event handler. I Still don't have access to the ProcessContext instance like I do in the expression builder. Is there some way to get to the ProcessContext instance through the object model?

  • You can just create a new instance of it:

     

     

    var pc = new ProcessContext();
    var folderId = pc.FolderId;
    

     

    iain

  • Hmmm. Odd. I would have thought something like that would be a singleton. Logically, there is only one "process context", right?

  • It couldn't be a singleton because there needs to be an instance per folder.

     

    Not really sure how the engine manages this though I'm afraid.

     

    Iain


  • Roryap wrote:
    Hmmm. Odd. I would have thought something like that would be a singleton. Logically, there is only one "process context", right?


    It actually is a singleto9n for each session. Change one instance of it, and you'll find the change reflected in all instances.
     It's just a slightly odd way to access it (IMO).

     

    You can do the same with a Process Business Object as well, since you can only have one process per session (or none, but that is a special case, with slightly different behaviour).

     

    I am sure it's not documented, however, but that puts it in fairly good company.