how to get data from smartobject


Badge +6

I created a smartobject from the User Role Manager Service. I am trying to get the list of users in a role using the Get Role User method. The method has a parameter called rolename that wants the name of the role. When i run the code, it tells me:

SmartObject property roleName is a required property for selected method GetRoleUsers. Value must be set.

Here is my code below:

ConnnectToSmartObjects(); //i connect to the server here



 



 



SmartObject smartobject = serverName.GetSmartObject("User_URM_Service"); SmartListMethod getlist = smartobject.ListMethods["GetRoleUsers"];
smartobject.MethodToExecute = getlist.Name;

Equals
mainfilter = new Equals();
mainfilter.Left =
new PropertyExpression("roleName", PropertyType.Text);
mainfilter.Right =
new ValueExpression(rolename, PropertyType.Text);
getlist.Filter = mainfilter;



 







 







 


SmartObjectList smoList = serverName.ExecuteList(smartobject); //error here



6 replies

Badge +9

What you want to do is set the properties of your smartobject, not the filter.  Something like smartobject.Properties["roleName"].Value = "Test";

Badge +6

i tried that first but got this error:  "Key could not be found in the collection."


I tried the code I posted on another smartobject and it worked (Process Instance)  using Originator as my input property. When i look at the SmartObject tester it shows Originator as a property.


However...when i look at Get Role Users in the smartobject tester, it lists the Role Name not as a property but as a Parameter. My initial thought is that this would be handled differently via code. Do you know if there is different code for a parameter input as opposed to a property input?

Badge +9

Well, since you are invoking a smartobject method, the name of the property should match how it appears on the method.  So in this case, I think the name would be "Role Name" or possibly "Role_Name" if it doesn't like spaces (I can't recall).  If that doesn't work, I will take a closer look at reproducing using that specific SmartObject.  Please let us know...

Badge +6

I tried both Role_Name and Role Name and neither worked.


I created this smartobject from the User Role Manager Service by right clicking on the service in the SmartObjects tester and creating it there. It then is listed under the method called Get Role Users in the newly created smartobject.


thanks

Badge +9

Pardon me, I wasn't very clear.  You want to use the "Parameters" collection off of the SmartMethod object, like this:


SourceCode.SmartObjects.Client.SmartObject smartObject = scs.GetSmartObject("User");
SourceCode.SmartObjects.Client.SmartListMethod smartMethod = smartObject.ListMethods["GetRoleUsers"];
smartObject.MethodToExecute = smartMethod.Name;
smartMethod.Parameters["roleName"].Value = "Test";
                   
scs.ExecuteListDataTable(smartObject);

Badge +6

Hey Tim,


thanks. that did the trick. I've got another issue with the API/smartobject that i will post soon. Perhaps you could answer that one too.


thanks again.

Reply