Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Highlighted
New Member
Posts: 20
Registered: ‎08-23-2010
Accepted Solution

SData - Resource objects in single Payload

[ Edited ]

I was wondering if something like this would be possible -- again, I am using the DataCSharpClientLib object.

 

I have a transaction where I am inserting an account into Saleslogix. There exists a number of "parent"-type Resource properties on the Account entity, such as the "ShippingAddress" for example.

 

Would it be possible to include the field values for ShippingAddress in the same payload as the Account insert?

 

So my code would look something like this:

 

.... read template/create payload ...

payload.Values("AccountName") = "ABC Company"
payload.Values("Type") = "ABC Company"
payload.Values("MainPhone") = "312-555-1212"

payload.Values("ShippingAddress.Address1") = "1111 East Street"
payload.Values("ShippingAddress.City") = "Chicago"
payload.Values("ShippingAddress.State") = "IL"

... call create entity ...

 

Does this make sense?  Is there a different way to do this? Or can i just not be done and needs to be two seperate transactions/payloads?

 

Thanks

Highlighted
Employee
Posts: 27
Registered: ‎08-06-2009

Re: SData - Resource objects in single Payload

You can do this with a nested payload, as follows (C#):

 

payload.Values["ShippingAddress"] =
    new SDataPayload {
        Values = {
            {"Address1""1111 East Street"},
            {"City""Chicago"},
            {"State""IL"}
        }
    };

Note that you don't need to set the ResourceName or Namespace properties for nested reference payloads.

 

If you're creating your payload using a template then you can include related templates using the include query argument.

 

/slx/dynamic/-/accounts/$template?include=ShippingAddress

The template returned will have a nested shipping address payload ready to hold values, as follows:

 

var shippingPayload = (SDataPayload)payload.Values["ShippingAddress"];
shippingPayload.Values["Address1"] = "1111 East Street";
shippingPayload.Values["City"] = "Chicago";
shippingPayload.Values["State"] = "IL";
Highlighted
New Member
Posts: 20
Registered: ‎08-23-2010

Re: SData - Resource objects in single Payload

Thanks - Just what I was looking for.. Now I have just one more somewhat related question..

 

How do you provide a foreign key when creating a new entry?

 

For example,

 

I am creating a Contact, and I need to supply it's AccountID. For the Saleslogix SData implementation, the Contact.AccountID field is not turned on for SData by default. Do I need to turn it on, or is there a different way I can supply it? Or I'm guessing I may would need to populate the Contact.Account object with a nested payload as you shown? Thanks!

Highlighted
Employee
Posts: 27
Registered: ‎08-06-2009

Re: SData - Resource objects in single Payload

A contact can be associated with an existing account using a nested payload with just the Key property set:

 

payload.Values["Account"] = new SDataPayload {Key = "AGHEA0002669"};
Highlighted
New Member
Posts: 20
Registered: ‎08-23-2010

Re: SData - Resource objects in single Payload

Thanks.. thats what I was thinking.. BTW the nested payloads from the first question worked perfectly.

Highlighted
Copper Contributor
Posts: 31
Registered: ‎04-08-2010

Re: SData - Resource objects in single Payload

We're trying to do the same thing, and have been struggling with it for a while.  I'm sure it's a syntax issue.  We've tried a nested payload, but just can't find a complete-enough example to go on.  Does someone have a more complete sample to share for adding an account and address, using SData nested payloads?  Or adding a contact and address?

Highlighted
Copper Super Contributor
Posts: 23
Registered: ‎08-17-2009

Re: SData - Resource objects in single Payload

Here you go:

 

        private void CreateAccountAndNestedAddressTest()
        {
            var service = new SDataService("http://10.40.240.183/sdata/slx/dynamic/-/") { UserName = "admin", Password = "" };
            var entry = new AtomEntry();

            var payload = new SDataPayload
            {
                ResourceName = "Account",
                Namespace = "http://schemas.sage.com/dynamic/2007",
                Values = {
                            {"AccountName", "_TestAccount"},
                            {"Address",
                                new SDataPayload
                                { 
                                    ResourceName = "Address", 
                                    Values = {
                                                {"Address1","_TestStreet1"},
                                                {"City", "Round Rock"},
                                                {"State", "Texas"}
                                    }
                                } 
                            }
                        }                    
            };


            entry.SetSDataPayload(payload);
            var request = new SDataSingleResourceRequest(service, entry){ResourceKind = "accounts"};
            AtomEntry result = new AtomEntry();
            try
            {
                result = request.Create();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.StackTrace);
                throw;
            }
        }

 

Highlighted
Copper Contributor
Posts: 31
Registered: ‎04-08-2010

Re: SData - Resource objects in single Payload

Thanks, Mark.  We tried your code and it works great!  Thank you, so much!  We were flying blind, until you sent your code.  Now ... do you think we can nest in three layers? Account

- Address (for the account)

- Contact

-  - Address (for the contact)

-  - ContactExtension (extension table of the contact)

 

We tested the bottom three, and that worked.

John

Highlighted
Bronze Super Contributor
Posts: 141
Registered: ‎02-22-2010

Re: SData - Resource objects in single Payload

Hi All,

When i try to insert account with account type as "Pending Customer" using sdata, my account is always getting inserted with type "customer". Could you please help. Its Urgent

Thanks,
Jack
Highlighted
Gold Super Contributor
Posts: 3,087
Registered: ‎03-19-2009

Re: SData - Resource objects in single Payload

Business Rules..

--
RJ Ledger - rjledger@rjlSystems.net +1 603.369.3047 x101

".. Innovators in Mobility - Experts in Workflow Automation..."
http://www.rjlSystems.net - blog: www.rjlSystems.net/blog.html