Showing results for 
Search instead for 
Do you mean 

Working with groups with Sdata.

by garnold on ‎11-14-2011 06:12 AM

Sdata is the tool of choice when it comes to integrating with SalesLogix and soon most of the products Sage owns. Here are a few examples of working with group information. Keep a lookout for a full example Smiley Happy

 

So once a user logs into SalesLogix via an Sdata service context has been astablished. This means any records that the logged in user has access to can be manipulated but this does not stop there. Only the groups that user has access to can be accessed as well. Below is a method that would return all the groups a user has access to from within a specific group family.

 

private void LoadGroups(string FamilyName)
        {
            //Create the actually SData call
            SDataService service = new SDataService(txtServer.Text + ":" + txtPort.Text + "/sdata/slx/system/-/",txtUserName.Text,txtPassword.Text);

            SDataResourceCollectionRequest sdataCollection = new SDataResourceCollectionRequest(service)
            {
                ResourceKind = "groups",
                QueryValues = {
                        {"where", "family eq '" + FamilyName + "'"}
                    },
            };

            AtomFeed feed = sdataCollection.Read();

            cboGroups.Text = "";
            cboGroups.Items.Clear();
            foreach (AtomEntry tempEntry in feed.Entries)
            {
                SDataPayload group = (SDataPayload)tempEntry.GetSDataPayload();


                cboGroups.Items.Add(new MyListItems { Display = group.Values["name"].ToString(), Value = group.Key });
                cboGroups.DisplayMember = "Display";   
            }
        }

 

A few things to note here...

 

1. Notice that the URL is different then what you might be expecting. You need to direct you request to the "SYSTEM" endpoint.

 

2. As you can see you simply just pass the family name to this Sdata call which in turn gives you a collection of groups the user can access.

 

3. I'm using a custom class called "MyListItems" to store some of the group data that is returned but you can do what ever you like with it.

 

4. Important to note that you now have the group id's. You can now pass those id's to another call which will return even more information. Let's check that out now Smiley Happy

 

This next call is really cool! It will return the layout information of a group. So what this means is pretty much all the metadata of the group. Fields, column width, types and pretty much all the cool stuff you would want to know about a group's layout. Here is a snippet of code that grabs all the fields in a group layout.

 

private void LoadFieldNames()
        {
            MyListItems group = (MyListItems)cboGroups.SelectedItem;

            var request = new SDataRequest("http://localhost:3333/sdata/slx/system/-/groups('" + group.Value + "')?include=layout") { UserName = "admin" };

            var response = request.GetResponse();
            var entry = (AtomEntry)response.Content;
            SDataPayload groupPayload = entry.GetSDataPayload();

            SDataPayloadCollection layoutCollection = (SDataPayloadCollection)groupPayload.Values["layout"];

            ckblGroupFields.Items.Clear();

            foreach (SDataPayload pl in layoutCollection)
            {
                if (!String.IsNullOrEmpty(pl.Values["caption"].ToString()))
                {
                    ckblGroupFields.Items.Add(new MyListItems { Display = pl.Values["caption"].ToString(), Value = pl.Values["alias"].ToString() });
                }
            }

            ckblGroupFields.DisplayMember = "Display";
        }

 

Again some points to note here...

 

1. Just like above the endpoint is to the "SYSTEM" endpoint.

2. The call is pretty simple, just pass the id of the group and the group is returned. Not to much different than calling an account or any other entity.

 

Hope these are useful to you! Stay tuned for a full example that exports data via groups Smiley Happy (example is pretty much built, just needs some cleanup hahaha)

Comments
by SanDegan
on ‎03-26-2012 11:23 AM

I am very new to SData and this is cool.

 

When I built a test app with the above code, I only get on Group returned.  I set the user creds to Admin.  I would think I should get all groups. Why do I only get 1.  The plugin table has 42 distinct group descriptions.

 

In the LoadFieldNames, SDataRequest is not part of the SageSData lib.  What is that?

 

Jeff

 

 

 

by SanDegan
on ‎03-26-2012 11:36 AM

FYI I am using VisualStudio 2010 (C#).  I am using the SDClient Library obtained from using NuGet.  The version is stated as 1.2.2.1335 for .net 3.5

 

by markanderson
on ‎03-27-2012 10:31 AM

Jeff -  

 

This line is what is causing you to get only one record back:

 

var request = new SDataRequest("http://localhost:3333/sdata/slx/syst​em/-/groups('" + group.Value + "')?include=layout") { UserName = "admin" };

The expression "group.Value" is probably the group ID, so it's only returning group selected by that ID.  If you'd like to get a list of groups, you can eliminate that expression and the statement will return a collection of groups.  However, there are several other things that will have to change in the code in order to accomodate a collection being returned as opposed to a single atom entry being returned.  Here is some code that goes out and gets a collection of groups:

 

var groupsRequest = newSDataRequest(@"http://10.40.244.1/sdata/slx/system/-/groups") { UserName = "admin", Password = "password"}; 

vargroupsResponse = groupsRequest.GetResponse(); 

var groupsFeed = (AtomFeed)groupsResponse.Content; 

foreach (var entry ingroupsFeed.Entries)

{

    varsdataPayload = entry.GetSDataPayload(); 

    Console.WriteLine("Retrieved Group: {0}", sdataPayload.Values["name"]);

}

Register Read Guidelines Request Partner or Employee Access

What's New in 8.1

Labels