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 12
Linked Modules 3
mattkol edited this page Dec 18, 2016
·
5 revisions
This sample usage shows how to read "Account" module entity collection data with linked modules (link "Cases" and "Bugs" modules). 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.
using SugarRestSharp;
using CustomModels;
using Newtonsoft.Json;
string url = "http://191.101.224.189/sugar/service/v4_1/rest.php";
string username = "will";
string password = "will";
var client = new SugarRestClient(url, username, password);
var request = new SugarRestRequest(RequestType.LinkedBulkRead);
request.Parameter = null;
request.Options.MaxResult = 3;
List<string> selectedFields = new List<string>();
selectedFields.Add("id");
selectedFields.Add("name");
selectedFields.Add("industry");
selectedFields.Add("website");
request.Options.SelectFields = selectedFields;
Dictionary<object, List<string>> linkedListInfo = new Dictionary<object, List<string>>();
List<string> selectCaseFields = new List<string>();
selectCaseFields.Add(nameof(Case.AccountId));
selectCaseFields.Add(nameof(Case.CaseNumber));
selectCaseFields.Add("description");
linkedListInfo[typeof(Case)] = selectCaseFields;
// Get all fields for Bug
linkedListInfo["Bugs"] = null;
request.Options.LinkedModules = linkedListInfo;
SugarRestResponse response = client.Execute<Account>(request);
using Newtonsoft.Json;
using SugarRestSharp.Models;
using System.Collections.Generic;
public class CustomAcccount : Account
{
[JsonProperty(PropertyName = "bugs")]
public virtual List<Bug> ContactLink { get; set; }
[JsonProperty(PropertyName = "cases")]
public virtual List<Case> CaseLink { get; set; }
}
Data = null
// Deserialize json data to custom object
List<CustomAcccount> customAccounts = JsonConvert.DeserializeObject<List<CustomAcccount>>(response.JData);
[
{
"id": "28270ac1-2a6b-e674-b751-5777b5c57439",
"name": "X-Sell Holdings",
"industry": "Banking",
"website": "www.qaqa.co.uk",
"cases": [
{
"account_id": "28270ac1-2a6b-e674-b751-5777b5c57439",
"case_number": "5",
"description": ""
}
],
"bugs": [
{
"id": "2f41ba6e-a574-6936-fbc1-5777b5df7671",
"name": "Warning is displayed in file after exporting",
"date_entered": "2016-07-02 12:36:44",
"date_modified": "2016-07-02 12:36:44",
"modified_user_id": "1",
"created_by": "1",
"description": "",
"deleted": "0",
"assigned_user_id": "seed_chris_id",
"bug_number": "5",
"type": "",
"status": "New",
"priority": "Medium",
"resolution": "",
"work_log": "",
"found_in_release": "",
"fixed_in_release": "",
"source": "",
"product_category": ""
}
]
},
{
"id": "54bf59bc-ec61-1860-a97e-5777b5e92066",
"name": "Southern Realty",
"industry": "Telecommunications",
"website": "www.veganqa.tv",
"cases": [
{
"account_id": "54bf59bc-ec61-1860-a97e-5777b5e92066",
"case_number": "41",
"description": ""
}
],
"bugs": [
{
"id": "620658be-78fa-8288-3805-5777b50710a6",
"name": "Error occurs while running count query",
"date_entered": "2016-07-02 12:36:44",
"date_modified": "2016-07-02 12:36:44",
"modified_user_id": "1",
"created_by": "1",
"description": "",
"deleted": "0",
"assigned_user_id": "seed_chris_id",
"bug_number": "41",
"type": "",
"status": "New",
"priority": "Low",
"resolution": "",
"work_log": "",
"found_in_release": "",
"fixed_in_release": "",
"source": "",
"product_category": ""
}
]
},
{
"id": "66a60fba-47e4-9a8c-0774-5777b5c6aac9",
"name": "A.G. Parr PLC",
"industry": "Shipping",
"website": "www.beanskid.it",
"cases": [
{
"account_id": "66a60fba-47e4-9a8c-0774-5777b5c6aac9",
"case_number": "47",
"description": ""
}
],
"bugs": [
{
"id": "72d01194-ce26-98a7-68c0-5777b50b1157",
"name": "Fatal error during installation",
"date_entered": "2016-07-02 12:36:44",
"date_modified": "2016-07-02 12:36:44",
"modified_user_id": "1",
"created_by": "1",
"description": "",
"deleted": "0",
"assigned_user_id": "seed_chris_id",
"bug_number": "47",
"type": "",
"status": "Pending",
"priority": "Low",
"resolution": "",
"work_log": "",
"found_in_release": "",
"fixed_in_release": "",
"source": "",
"product_category": ""
}
]
}
]
{
"resource": "",
"parameters": [
{
"name": "method",
"value": "get_entry_list",
"type": "GetOrPost"
},
{
"name": "input_type",
"value": "json",
"type": "GetOrPost"
},
{
"name": "response_type",
"value": "json",
"type": "GetOrPost"
},
{
"name": "rest_data",
"value": "{\"session\":\"g1mvto5llqlsd1lqih4ci6l331\",\"module_name\":\"Accounts\",\"query\":\"\",\"order_by\":\"\",\"offset\":0,\"select_fields\":[\"id\",\"name\",\"industry\",\"website\"],\"link_name_to_fields_array\":[{\"name\":\"cases\",\"value\":[\"account_id\",\"case_number\",\"description\"]},{\"name\":\"bugs\",\"value\":[\"id\",\"name\",\"date_entered\",\"date_modified\",\"modified_user_id\",\"created_by\",\"description\",\"deleted\",\"assigned_user_id\",\"bug_number\",\"type\",\"status\",\"priority\",\"resolution\",\"work_log\",\"found_in_release\",\"fixed_in_release\",\"source\",\"product_category\"]}],\"max_results\":3,\"deleted\":0,\"favorites\":false}",
"type": "GetOrPost"
},
{
"name": "Accept",
"value": "application\/json, application\/xml, text\/json, text\/x-json, text\/javascript, text\/xml",
"type": "HttpHeader"
}
],
"method": "POST",
"uri": "http:\/\/191.101.224.189\/sugar\/service\/v4_1\/rest.php"
}
{
"statusCode": 200,
"content": "{\"result_count\":3,\"total_count\":\"50\",\"next_offset\":3,\"entry_list\":[{\"id\":\"28270ac1-2a6b-e674-b751-5777b5c57439\",\"module_name\":\"Accounts\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"28270ac1-2a6b-e674-b751-5777b5c57439\"},\"name\":{\"name\":\"name\",\"value\":\"X-Sell Holdings\"},\"industry\":{\"name\":\"industry\",\"value\":\"Banking\"},\"website\":{\"name\":\"website\",\"value\":\"www.qaqa.co.uk\"}}},{\"id\":\"54bf59bc-ec61-1860-a97e-5777b5e92066\",\"module_name\":\"Accounts\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"54bf59bc-ec61-1860-a97e-5777b5e92066\"},\"name\":{\"name\":\"name\",\"value\":\"Southern Realty\"},\"industry\":{\"name\":\"industry\",\"value\":\"Telecommunications\"},\"website\":{\"name\":\"website\",\"value\":\"www.veganqa.tv\"}}},{\"id\":\"66a60fba-47e4-9a8c-0774-5777b5c6aac9\",\"module_name\":\"Accounts\",\"name_value_list\":{\"id\":{\"name\":\"id\",\"value\":\"66a60fba-47e4-9a8c-0774-5777b5c6aac9\"},\"name\":{\"name\":\"name\",\"value\":\"A.G. Parr PLC\"},\"industry\":{\"name\":\"industry\",\"value\":\"Shipping\"},\"website\":{\"name\":\"website\",\"value\":\"www.beanskid.it\"}}}],\"relationship_list\":[{\"link_list\":[{\"name\":\"cases\",\"records\":[{\"link_value\":{\"account_id\":{\"name\":\"account_id\",\"value\":\"28270ac1-2a6b-e674-b751-5777b5c57439\"},\"case_number\":{\"name\":\"case_number\",\"value\":\"5\"},\"description\":{\"name\":\"description\",\"value\":\"\"}}}]},{\"name\":\"bugs\",\"records\":[{\"link_value\":{\"id\":{\"name\":\"id\",\"value\":\"2f41ba6e-a574-6936-fbc1-5777b5df7671\"},\"name\":{\"name\":\"name\",\"value\":\"Warning is displayed in file after exporting\"},\"date_entered\":{\"name\":\"date_entered\",\"value\":\"2016-07-02 12:36:44\"},\"date_modified\":{\"name\":\"date_modified\",\"value\":\"2016-07-02 12:36:44\"},\"modified_user_id\":{\"name\":\"modified_user_id\",\"value\":\"1\"},\"created_by\":{\"name\":\"created_by\",\"value\":\"1\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"deleted\":{\"name\":\"deleted\",\"value\":\"0\"},\"assigned_user_id\":{\"name\":\"assigned_user_id\",\"value\":\"seed_chris_id\"},\"bug_number\":{\"name\":\"bug_number\",\"value\":\"5\"},\"type\":{\"name\":\"type\",\"value\":\"\"},\"status\":{\"name\":\"status\",\"value\":\"New\"},\"priority\":{\"name\":\"priority\",\"value\":\"Medium\"},\"resolution\":{\"name\":\"resolution\",\"value\":\"\"},\"work_log\":{\"name\":\"work_log\",\"value\":\"\"},\"found_in_release\":{\"name\":\"found_in_release\",\"value\":\"\"},\"fixed_in_release\":{\"name\":\"fixed_in_release\",\"value\":\"\"},\"source\":{\"name\":\"source\",\"value\":\"\"},\"product_category\":{\"name\":\"product_category\",\"value\":\"\"}}}]}]},{\"link_list\":[{\"name\":\"cases\",\"records\":[{\"link_value\":{\"account_id\":{\"name\":\"account_id\",\"value\":\"54bf59bc-ec61-1860-a97e-5777b5e92066\"},\"case_number\":{\"name\":\"case_number\",\"value\":\"41\"},\"description\":{\"name\":\"description\",\"value\":\"\"}}}]},{\"name\":\"bugs\",\"records\":[{\"link_value\":{\"id\":{\"name\":\"id\",\"value\":\"620658be-78fa-8288-3805-5777b50710a6\"},\"name\":{\"name\":\"name\",\"value\":\"Error occurs while running count query\"},\"date_entered\":{\"name\":\"date_entered\",\"value\":\"2016-07-02 12:36:44\"},\"date_modified\":{\"name\":\"date_modified\",\"value\":\"2016-07-02 12:36:44\"},\"modified_user_id\":{\"name\":\"modified_user_id\",\"value\":\"1\"},\"created_by\":{\"name\":\"created_by\",\"value\":\"1\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"deleted\":{\"name\":\"deleted\",\"value\":\"0\"},\"assigned_user_id\":{\"name\":\"assigned_user_id\",\"value\":\"seed_chris_id\"},\"bug_number\":{\"name\":\"bug_number\",\"value\":\"41\"},\"type\":{\"name\":\"type\",\"value\":\"\"},\"status\":{\"name\":\"status\",\"value\":\"New\"},\"priority\":{\"name\":\"priority\",\"value\":\"Low\"},\"resolution\":{\"name\":\"resolution\",\"value\":\"\"},\"work_log\":{\"name\":\"work_log\",\"value\":\"\"},\"found_in_release\":{\"name\":\"found_in_release\",\"value\":\"\"},\"fixed_in_release\":{\"name\":\"fixed_in_release\",\"value\":\"\"},\"source\":{\"name\":\"source\",\"value\":\"\"},\"product_category\":{\"name\":\"product_category\",\"value\":\"\"}}}]}]},{\"link_list\":[{\"name\":\"cases\",\"records\":[{\"link_value\":{\"account_id\":{\"name\":\"account_id\",\"value\":\"66a60fba-47e4-9a8c-0774-5777b5c6aac9\"},\"case_number\":{\"name\":\"case_number\",\"value\":\"47\"},\"description\":{\"name\":\"description\",\"value\":\"\"}}}]},{\"name\":\"bugs\",\"records\":[{\"link_value\":{\"id\":{\"name\":\"id\",\"value\":\"72d01194-ce26-98a7-68c0-5777b50b1157\"},\"name\":{\"name\":\"name\",\"value\":\"Fatal error during installation\"},\"date_entered\":{\"name\":\"date_entered\",\"value\":\"2016-07-02 12:36:44\"},\"date_modified\":{\"name\":\"date_modified\",\"value\":\"2016-07-02 12:36:44\"},\"modified_user_id\":{\"name\":\"modified_user_id\",\"value\":\"1\"},\"created_by\":{\"name\":\"created_by\",\"value\":\"1\"},\"description\":{\"name\":\"description\",\"value\":\"\"},\"deleted\":{\"name\":\"deleted\",\"value\":\"0\"},\"assigned_user_id\":{\"name\":\"assigned_user_id\",\"value\":\"seed_chris_id\"},\"bug_number\":{\"name\":\"bug_number\",\"value\":\"47\"},\"type\":{\"name\":\"type\",\"value\":\"\"},\"status\":{\"name\":\"status\",\"value\":\"Pending\"},\"priority\":{\"name\":\"priority\",\"value\":\"Low\"},\"resolution\":{\"name\":\"resolution\",\"value\":\"\"},\"work_log\":{\"name\":\"work_log\",\"value\":\"\"},\"found_in_release\":{\"name\":\"found_in_release\",\"value\":\"\"},\"fixed_in_release\":{\"name\":\"fixed_in_release\",\"value\":\"\"},\"source\":{\"name\":\"source\",\"value\":\"\"},\"product_category\":{\"name\":\"product_category\",\"value\":\"\"}}}]}]}]}",
"headers": [
{
"Name": "Pragma",
"Value": "no-cache",
"Type": 3,
"ContentType": null
},
{
"Name": "Content-Length",
"Value": "4929",
"Type": 3,
"ContentType": null
},
{
"Name": "Cache-Control",
"Value": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
"Type": 3,
"ContentType": null
},
{
"Name": "Content-Type",
"Value": "application\/json; charset=UTF-8",
"Type": 3,
"ContentType": null
},
{
"Name": "Date",
"Value": "Sun, 18 Dec 2016 12:38:21 GMT",
"Type": 3,
"ContentType": null
},
{
"Name": "Expires",
"Value": "Thu, 19 Nov 1981 08:52:00 GMT",
"Type": 3,
"ContentType": null
},
{
"Name": "Set-Cookie",
"Value": "PHPSESSID=g1mvto5llqlsd1lqih4ci6l331; path=\/",
"Type": 3,
"ContentType": null
},
{
"Name": "Server",
"Value": "Apache\/2.4.7 (Ubuntu)",
"Type": 3,
"ContentType": null
},
{
"Name": "X-Powered-By",
"Value": "PHP\/5.5.9-1ubuntu4.17",
"Type": 3,
"ContentType": null
}
],
"responseUri": "http:\/\/191.101.224.189\/sugar\/service\/v4_1\/rest.php",
"errorMessage": null
}
SugarRestSharp
- Home
- Request
- Request Types
- Request Options
- 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