PowerBuilder
PowerBuilder
SugarCRM Create a Record List
See more SugarCRM Examples
Create a record list in Sugar consisting of a set of ids.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
oleobject loo_JsonReq
oleobject loo_SbReq
oleobject loo_SbJson
oleobject loo_Json
string ls_Id
string ls_Assigned_user_id
string ls_Module_name
string ls_Date_modified
integer i
integer li_Count_i
string ls_StrVal
li_Success = 0
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Rest.Connect("your.site.domain",443,1,1)
if li_Success <> 1 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
loo_Rest.AddHeader("Cache-Control","no-cache")
loo_Rest.AddHeader("OAuth-Token","<access_token>")
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
loo_JsonReq = create oleobject
li_rc = loo_JsonReq.ConnectToNewObject("Chilkat.JsonObject")
loo_JsonReq.UpdateString("records[0]","f16760a4-3a52-f77d-1522-5703ca28925f")
loo_JsonReq.UpdateString("records[1]","ec409fbb-2b22-4f32-7fa1-5703caf78dc3")
// The JSON request body created by the above code:
// {
// "records": [
// "f16760a4-3a52-f77d-1522-5703ca28925f",
// "ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
// ]
// }
loo_SbReq = create oleobject
li_rc = loo_SbReq.ConnectToNewObject("Chilkat.StringBuilder")
loo_JsonReq.EmitSb(loo_SbReq)
loo_Rest.AddHeader("Content-Type","application/json")
loo_SbJson = create oleobject
li_rc = loo_SbJson.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Rest.FullRequestSb("POST","/rest/v10/Accounts/record_list",loo_SbReq,loo_SbJson)
if li_Success <> 1 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_JsonReq
destroy loo_SbReq
destroy loo_SbJson
return
end if
if loo_Rest.ResponseStatusCode <> 200 then
Write-Debug "Received error response code: " + string(loo_Rest.ResponseStatusCode)
Write-Debug "Response body:"
Write-Debug loo_SbJson.GetAsString()
destroy loo_Rest
destroy loo_JsonReq
destroy loo_SbReq
destroy loo_SbJson
return
end if
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.LoadSb(loo_SbJson)
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
ls_Id = loo_Json.StringOf("id")
ls_Assigned_user_id = loo_Json.StringOf("assigned_user_id")
ls_Module_name = loo_Json.StringOf("module_name")
ls_Date_modified = loo_Json.StringOf("date_modified")
i = 0
li_Count_i = loo_Json.SizeOfArray("records")
do while i < li_Count_i
loo_Json.I = i
ls_StrVal = loo_Json.StringOf("records[i]")
i = i + 1
loop
// A sample JSON response body that is parsed by the above code:
// {
// "id": "ef963176-4845-bc55-b03e-570430b4173c",
// "assigned_user_id": "1",
// "module_name": "Accounts",
// "records": [
// "f16760a4-3a52-f77d-1522-5703ca28925f",
// "ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
// ],
// "date_modified": "2016-04-05 21:39:19"
// }
Write-Debug "Example Completed."
destroy loo_Rest
destroy loo_JsonReq
destroy loo_SbReq
destroy loo_SbJson
destroy loo_Json