SmartObjectList


Badge +1

I am writing a webservice to expose data collected in my process to a website.


I am access the data using the GetList method of the particular SmartObject. When I use a SQLDataReader, I am able to retrieve my results, but when I access this in code, I get no results returned, and no errors. If I change it to use the Load method and specify the parameter value, then I get results returned. I have even used the Developers Reference that comes with K2 [blackpearl] to check that the code is correct. Perhaps I'm overlooking something, or doing something wrong. Below is the code, can you see anything wrong?


 public Vacancy GetAllVacancies()
    {
        Vacancy vac = new Vacancy();
        string _user = ConfigurationManager.AppSettings["User"];
        string _server = ConfigurationManager.AppSettings["Host"];
        string _password = ConfigurationManager.AppSettings["Password"];


        SourceCode.SmartObjects.Client.SmartObjectClientServer serverName = new SourceCode.SmartObjects.Client.SmartObjectClientServer();


        SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder connectionString = new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();


        //build the connection string
        connectionString.Authenticate = true;
        connectionString.Host = _server;
        connectionString.Integrated = true;
        connectionString.IsPrimaryLogin = true;
        connectionString.Port = 5555;
        connectionString.UserID = _user;
        connectionString.Password = _password;


        serverName.CreateConnection();
        serverName.Connection.Open(connectionString.ToString());


        try
        {
            SmartObject smoVacancy = serverName.GetSmartObject("Vacancy");


            smoVacancy.MethodToExecute ="GetList";


            SmartObjectList smoList = serverName.ExecuteList(smoVacancy);


            foreach (SmartObject smo in smoList.SmartObjectsList)
            {
                vac.AdvertID = Convert.ToInt32(smoVacancy.Properties["AdvertID"].Value);
                vac.NampeProfile = smoVacancy.Properties["NameProfile"].Value;
            }
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
        finally
        {
            serverName.Connection.Close();
        }
        return vac;
      
    }


2 replies

Badge +9

I think the issue is that you are grabbing data from the incorrect object.


Notice the bolded items below.  You are in a foreach loop where you are getting the objects int the returned list collection and setting it to a variable called 'smo'. However you are attempting to retreive the data from a varable called 'smoVacancy'. 


            foreach (SmartObject smo in smoList.SmartObjectsList)
            {
                vac.AdvertID = Convert.ToInt32(smoVacancy.Properties["AdvertID"].Value);
                vac.NampeProfile = smoVacancy.Properties["NameProfile"].Value;
            }
 


The difference betwen a list and and a Load, is that the Load would populate the properties in the intitially declared SmartObject (in this case smoVacancy). A list will generate a collection of SmartObject objects (in your example it is smoList).


I think if you change it to look like below you should see some results:


            foreach (SmartObject smo in smoList.SmartObjectsList)
            {
                vac.AdvertID = Convert.ToInt32(smo.Properties["AdvertID"].Value);
                vac.NampeProfile = smo.Properties["NameProfile"].Value;
            }
 


 HTH.

Badge +1

 Thanks! You were correct, problem solved!

Reply