Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
New Member
Posts: 8
Registered: ‎04-07-2011

How to add a picklist item through sData

Hi, does anyone know how I can add a new picklist item through sData?

 

I tried the following so far:

 

 

        private static void addProductFamilyToSaleslogix(string familyName, string picklistID)
        {
            try
            {
                SDataService service = new SDataService(_url + "/slx/system/-/", _user, _password);

                SDataResourceCollectionRequest sdataCollection = new SDataResourceCollectionRequest(service)
                {
                    ResourceKind = "pickLists",
                    QueryValues = {
                        {"where", "name eq 'Product Family'"},
                        {"select", "items/*"}
                }
                };

                AtomFeed feed = sdataCollection.Read();
                AtomEntry tempEntry = feed.Entries.First();
                SDataPayload payload = (SDataPayload)tempEntry.GetSDataPayload();
                SDataPayloadCollection picklistitems = (SDataPayloadCollection)payload.Values["items"];

                var family = new SDataPayload
                {
                    ResourceName = "pickListItem",
                    Values = { 
                { "text", familyName }
                }
                };

                //picklistitems.Insert(picklistitems.Count, family);
                picklistitems.Add(family);

                var entry = new AtomEntry();
                entry.SetSDataPayload(payload);

                var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "pickLists" };
                request.ResourceSelector = string.Format("'{0}'", payload.Key);
                AtomEntry result = request.Update();
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }

        }

 

Silver Contributor
Posts: 835
Registered: ‎03-24-2009

Re: How to add a picklist item through sData

No idea.....and hopefully the user is ALWAYS the Admin......(you are aware of the implications if not?)

 

Seems to me you might need to populate the (int)  ID, ShortText fields as well.....

RJ Samp