This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Linked Modules 2
mattkol edited this page Jan 21, 2017
·
2 revisions
This sample usage shows how to read "Accounts" module entity collection data with linked modules (link "Contacts" module). For more request options make changes to the [Options parameter](Request Options).
This implements the get_entry_list SugarCRM REST API method setting the link_name_to_fields_array parameter.
package com.sugaronrest.tests;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sugaronrest.*;
import com.sugaronrest.modules.*;
import com.sugaronrest.tests.custommodels.CustomAcccount2;
import com.sugaronrest.utils.JsonObjectMapper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
String url = "http://demo.suiteondemand.com/service/v4_1/rest.php";
String username = "will";
String password = "will";
SugarRestClient client = new SugarRestClient(url, username, password);
SugarRestRequest request = new SugarRestRequest(RequestType.LinkedBulkRead);
request.setModuleName("Accounts");
request.getOptions().setMaxResult(5);
List<String> selectedFields = new ArrayList<String>();
selectedFields.add(NameOf.Accounts.Id);
selectedFields.add(NameOf.Accounts.Name);
selectedFields.add(NameOf.Accounts.Industry);
selectedFields.add(NameOf.Accounts.Website);
selectedFields.add(NameOf.Accounts.ShippingAddressCity);
request.getOptions().setSelectFields(selectedFields);
Map<Object, List<String>> linkedListInfo = new HashMap<Object, List<String>>();
List<String> selectContactFields = new ArrayList<String>();
selectContactFields.add(NameOf.Contacts.FirstName);
selectContactFields.add(NameOf.Contacts.LastName);
selectContactFields.add(NameOf.Contacts.Title);
selectContactFields.add(NameOf.Contacts.Description);
selectContactFields.add(NameOf.Contacts.PrimaryAddressPostalcode);
linkedListInfo.put(Contacts.class, selectContactFields);
request.getOptions().setLinkedModules(linkedListInfo);
SugarRestResponse response = client.execute(request);
package com.sugaronrest.tests.custommodels;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.sugaronrest.modules.Accounts;
import com.sugaronrest.modules.Contacts;
import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class CustomAcccount2 extends Accounts {
public List<Contacts> getContactLink() {
return contactLink;
}
public void setContactLink(List<Contacts> value) {
contactLink = value;
}
@JsonProperty("contacts")
private List<Contacts> contactLink;
}
getData() = null;
String jsonData = response.getJData();
// Deserialize json data to custom object
ObjectMapper mapper = JsonObjectMapper.getMapper();
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, CustomAcccount2.class) ;
List<CustomAcccount2> customAccounts = mapper.readValue(jsonData, type);
[
{
"website": "www.beanssection.edu",
"name": "Lexington Shores Corp",
"industry": "Energy",
"id": "1038295e-6960-3a32-289d-5876627679e2",
"shipping_address_city": "Cupertino",
"contacts": [
{
"primary_address_postalcode": "82438",
"last_name": "Schloss",
"description": "",
"title": "VP Operations",
"first_name": "Mamie"
},
{
"primary_address_postalcode": "76158",
"last_name": "Dames",
"description": "",
"title": "VP Operations",
"first_name": "Suzette"
}
]
},
{
"website": "www.hrinfo.com",
"name": "P Piper & Sons",
"industry": "Insurance",
"id": "13441586-9c1d-66d7-89ac-587662562409",
"shipping_address_city": "Salt Lake City",
"contacts": [
{
"primary_address_postalcode": "39501",
"last_name": "Ashurst",
"description": "",
"title": "Director Operations",
"first_name": "Amie"
},
{
"primary_address_postalcode": "22015",
"last_name": "Nugent",
"description": "",
"title": "Senior Product Manager",
"first_name": "Carol"
}
]
},
{
"website": "www.sugarphone.tv",
"name": "SuperG Tech",
"industry": "Finance",
"id": "26d6061c-dceb-ffef-ae86-58766247c253",
"shipping_address_city": "Salt Lake City",
"contacts": [
{
"primary_address_postalcode": "46432",
"last_name": "Patel",
"description": "",
"title": "Director Sales",
"first_name": "Susan"
},
{
"primary_address_postalcode": "19541",
"last_name": "Delong",
"description": "",
"title": "VP Sales",
"first_name": "Felipe"
}
]
},
{
"website": "www.sectionsales.org",
"name": "Nelson Inc",
"industry": "Media",
"id": "2750c059-4f18-23d0-7b75-5876628fd436",
"shipping_address_city": "Denver",
"contacts": [
{
"primary_address_postalcode": "23024",
"last_name": "Landes",
"description": "",
"title": "Senior Product Manager",
"first_name": "Dorothea"
},
{
"primary_address_postalcode": "36805",
"last_name": "Schubert",
"description": "",
"title": "Director Operations",
"first_name": "Laurel"
},
{
"primary_address_postalcode": "94568",
"last_name": "Laney",
"description": "",
"title": "IT Developer",
"first_name": "Jodi"
}
]
},
{
"website": "www.veganqa.info",
"name": "5D Investments",
"industry": "Consulting",
"id": "290a517c-9470-e663-775b-58766246fcb3",
"shipping_address_city": "San Mateo",
"contacts": [
{
"primary_address_postalcode": "79191",
"last_name": "Henriques",
"description": "",
"title": "Senior Product Manager",
"first_name": "Taylor"
},
{
"primary_address_postalcode": "36584",
"last_name": "Dubuque",
"description": "",
"title": "VP Sales",
"first_name": "Ezra"
},
{
"primary_address_postalcode": "18365",
"last_name": "Hick",
"description": "",
"title": "VP Operations",
"first_name": "Rachel"
},
{
"primary_address_postalcode": "31936",
"last_name": "Dunlap",
"description": "",
"title": "VP Operations",
"first_name": "Kasey"
},
{
"primary_address_postalcode": "39704",
"last_name": "Jayne",
"description": "",
"title": "IT Developer",
"first_name": "Morgan"
},
{
"primary_address_postalcode": "30278",
"last_name": "Lansford",
"description": "",
"title": "IT Developer",
"first_name": "Stanford"
},
{
"primary_address_postalcode": "97942",
"last_name": "Beresford",
"description": "",
"title": "VP Sales",
"first_name": "Allie"
}
]
}
]
{
"method": "get_entry_list",
"input_type": "json",
"response_type": "json",
"rest_data": {
"session": "asc1tgc9b26h435c42socfmd65",
"module_name": "Accounts",
"query": "",
"order_by": "",
"offset": 0,
"select_fields": [
"id",
"name",
"industry",
"website",
"shipping_address_city"
],
"link_name_to_fields_array": [
{
"name": "contacts",
"value": [
"first_name",
"last_name",
"title",
"description",
"primary_address_postalcode"
]
}
],
"max_results": 5,
"deleted": 0,
"favorites": false
}
}
{
"total_count": "50",
"relationship_list": [
{
"link_list": [
{
"records": [
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "82438"
},
"last_name": {
"name": "last_name",
"value": "Schloss"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "VP Operations"
},
"first_name": {
"name": "first_name",
"value": "Mamie"
}
}
},
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "76158"
},
"last_name": {
"name": "last_name",
"value": "Dames"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "VP Operations"
},
"first_name": {
"name": "first_name",
"value": "Suzette"
}
}
}
],
"name": "contacts"
}
]
},
{
"link_list": [
{
"records": [
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "39501"
},
"last_name": {
"name": "last_name",
"value": "Ashurst"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "Director Operations"
},
"first_name": {
"name": "first_name",
"value": "Amie"
}
}
},
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "22015"
},
"last_name": {
"name": "last_name",
"value": "Nugent"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "Senior Product Manager"
},
"first_name": {
"name": "first_name",
"value": "Carol"
}
}
}
],
"name": "contacts"
}
]
},
{
"link_list": [
{
"records": [
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "46432"
},
"last_name": {
"name": "last_name",
"value": "Patel"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "Director Sales"
},
"first_name": {
"name": "first_name",
"value": "Susan"
}
}
},
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "19541"
},
"last_name": {
"name": "last_name",
"value": "Delong"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "VP Sales"
},
"first_name": {
"name": "first_name",
"value": "Felipe"
}
}
}
],
"name": "contacts"
}
]
},
{
"link_list": [
{
"records": [
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "23024"
},
"last_name": {
"name": "last_name",
"value": "Landes"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "Senior Product Manager"
},
"first_name": {
"name": "first_name",
"value": "Dorothea"
}
}
},
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "36805"
},
"last_name": {
"name": "last_name",
"value": "Schubert"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "Director Operations"
},
"first_name": {
"name": "first_name",
"value": "Laurel"
}
}
},
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "94568"
},
"last_name": {
"name": "last_name",
"value": "Laney"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "IT Developer"
},
"first_name": {
"name": "first_name",
"value": "Jodi"
}
}
}
],
"name": "contacts"
}
]
},
{
"link_list": [
{
"records": [
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "79191"
},
"last_name": {
"name": "last_name",
"value": "Henriques"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "Senior Product Manager"
},
"first_name": {
"name": "first_name",
"value": "Taylor"
}
}
},
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "36584"
},
"last_name": {
"name": "last_name",
"value": "Dubuque"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "VP Sales"
},
"first_name": {
"name": "first_name",
"value": "Ezra"
}
}
},
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "18365"
},
"last_name": {
"name": "last_name",
"value": "Hick"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "VP Operations"
},
"first_name": {
"name": "first_name",
"value": "Rachel"
}
}
},
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "31936"
},
"last_name": {
"name": "last_name",
"value": "Dunlap"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "VP Operations"
},
"first_name": {
"name": "first_name",
"value": "Kasey"
}
}
},
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "39704"
},
"last_name": {
"name": "last_name",
"value": "Jayne"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "IT Developer"
},
"first_name": {
"name": "first_name",
"value": "Morgan"
}
}
},
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "30278"
},
"last_name": {
"name": "last_name",
"value": "Lansford"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "IT Developer"
},
"first_name": {
"name": "first_name",
"value": "Stanford"
}
}
},
{
"link_value": {
"primary_address_postalcode": {
"name": "primary_address_postalcode",
"value": "97942"
},
"last_name": {
"name": "last_name",
"value": "Beresford"
},
"description": {
"name": "description",
"value": ""
},
"title": {
"name": "title",
"value": "VP Sales"
},
"first_name": {
"name": "first_name",
"value": "Allie"
}
}
}
],
"name": "contacts"
}
]
}
],
"entry_list": [
{
"name_value_list": {
"website": {
"name": "website",
"value": "www.beanssection.edu"
},
"name": {
"name": "name",
"value": "Lexington Shores Corp"
},
"industry": {
"name": "industry",
"value": "Energy"
},
"id": {
"name": "id",
"value": "1038295e-6960-3a32-289d-5876627679e2"
},
"shipping_address_city": {
"name": "shipping_address_city",
"value": "Cupertino"
}
},
"id": "1038295e-6960-3a32-289d-5876627679e2",
"module_name": "Accounts"
},
{
"name_value_list": {
"website": {
"name": "website",
"value": "www.hrinfo.com"
},
"name": {
"name": "name",
"value": "P Piper & Sons"
},
"industry": {
"name": "industry",
"value": "Insurance"
},
"id": {
"name": "id",
"value": "13441586-9c1d-66d7-89ac-587662562409"
},
"shipping_address_city": {
"name": "shipping_address_city",
"value": "Salt Lake City"
}
},
"id": "13441586-9c1d-66d7-89ac-587662562409",
"module_name": "Accounts"
},
{
"name_value_list": {
"website": {
"name": "website",
"value": "www.sugarphone.tv"
},
"name": {
"name": "name",
"value": "SuperG Tech"
},
"industry": {
"name": "industry",
"value": "Finance"
},
"id": {
"name": "id",
"value": "26d6061c-dceb-ffef-ae86-58766247c253"
},
"shipping_address_city": {
"name": "shipping_address_city",
"value": "Salt Lake City"
}
},
"id": "26d6061c-dceb-ffef-ae86-58766247c253",
"module_name": "Accounts"
},
{
"name_value_list": {
"website": {
"name": "website",
"value": "www.sectionsales.org"
},
"name": {
"name": "name",
"value": "Nelson Inc"
},
"industry": {
"name": "industry",
"value": "Media"
},
"id": {
"name": "id",
"value": "2750c059-4f18-23d0-7b75-5876628fd436"
},
"shipping_address_city": {
"name": "shipping_address_city",
"value": "Denver"
}
},
"id": "2750c059-4f18-23d0-7b75-5876628fd436",
"module_name": "Accounts"
},
{
"name_value_list": {
"website": {
"name": "website",
"value": "www.veganqa.info"
},
"name": {
"name": "name",
"value": "5D Investments"
},
"industry": {
"name": "industry",
"value": "Consulting"
},
"id": {
"name": "id",
"value": "290a517c-9470-e663-775b-58766246fcb3"
},
"shipping_address_city": {
"name": "shipping_address_city",
"value": "San Mateo"
}
},
"id": "290a517c-9470-e663-775b-58766246fcb3",
"module_name": "Accounts"
}
],
"result_count": 5,
"next_offset": 5
}
SugarOnRest
- Home
- Request
- Request Types
- Request Options
- Response
- Error Response
- Read Module By Id
- Read Module Collection By Page
- Read Module Collection
- Create Module
- Create Module Collection
- Update Module
- Update Module Collection
- Delete Module
- Linked Modules 1
- Linked Modules 2
- Linked Modules 3
- Query Options 1
- Query Options 2
- Query Options 3