Calling a SmartObject method from inside a workflow code event

  • 22 February 2008
  • 6 replies
  • 0 views

Badge +7

Currently i'm doing something like this:


        public string runSPGetEmailSmartObject(string userName, string connString)


        {


            string userMail = "";


            string smartObjectName = "SPUser";


            string smartObjectMethodName = "Read";


 


            try


            {


                // create smart object server client to query smartobjects


                SmartObjectClientServer soServer = new SmartObjectClientServer();


 


                soServer.CreateConnection();


                soServer.Connection.Open(connString);


 


                //Instantiate SmartObject


                SmartObject so = soServer.GetSmartObject(smartObjectName);


 


                so.Properties["LoginName"].Value = userName;


                so.MethodToExecute = smartObjectMethodName;


                soServer.ExecuteScalar(so);


 


                userMail = so.Properties["Email"].Value;


            }


            catch (Exception Ex)


            {


                Console.WriteLine(Ex.Message);


            }


 


            return userMail;


        }


inside the workflow, which is identical to how I would do it if I was to call a SmartObject method from a standalone ASPX page.


Is there a more efficient way of doing this from inside a workflow code event. Currently i'm having to formulate a connection string which I feel I shouldn't need to create as the code runs in the context of the workflow.


any advice greatfully recieved


Martin.


 


 


6 replies

Badge +11
Have you tried using the SmartObject Event Wizard in the toolbox?  From your code example, I believe you could you could use the event to accomplish the same thing with no code.  If you do really need to use code, you might try pulling the "SmartObject Server" entry from the string table for the connection string.
Badge +7

Hi DavidL,


yes I could use the SmartObject event wizard, however, i'm actually trying to programatically calculate a dynamic field that isn't possible in the SmartObject event wizard.


Now all I need to do is work out how to get stuff from the string table..


 Martin

Badge +9

Martin,


When you say '... get stuff from the String Table." do you mean how to programatically retrieve a string table/environment value from within the Server event?


 If so, you should be able to retrieve it via:


    string strSomeValue = K2.StringTable["YOUR ENVIRONMENT FIELD NAME HERE"] ;


HTH.


Bob

Badge +7

Hi Bob,


 yes that's exactly what I meant. thanks


Martin

Badge +3

I was doing the same thing until I realized that calling the smart object was to much overhead in the codebehind. I used a directorysearcher to return the email. It seems allot quicker in any case.....


 


static void Main(string[] args)
        {
          
            string s = runSPGetEmailSmartObject("domainuser1; domainuser2; domainuser3");
           
        }



        private static string runSPGetEmailSmartObject(string ccUsers)
        {
            char[] delimiters = new char[] { ';' };
            string[] usernames = ccUsers.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
            string userMail = "";
            string formattedusers = "";


            try
            {


                foreach (string s in usernames)
                {
                    string snew = s.ToString();
                    snew = snew.Replace("CONSOLIDATED"

Badge +4

In early days, I have implemented my own AD webservice to do most of the tasks. K2 has improved their AD SMO a lot in recent days. Still in exceptional case  I was forced to use my own custom code instead of SMO. I would avoid this situation mostly.


e.g Scenarios:


For one of my client I was forced to update certain field in AD which was not exposed by K2 AD SMO.


Execute the Custom SMO in code behind because I was forced to find the field name dynamically by combining more than one variables. If u want to execute the SMO, you cant pass the key value pair dynamically. Key is predetermined and you can pass only the value for a given key/SMO property.


NathanPillai

Reply