Xbase++
Xbase++
SugarCRM Filtering Records
See more SugarCRM Examples
Export records and filter.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL oJsonReq
LOCAL oSbReq
LOCAL oSbJson
LOCAL oJson
LOCAL nNext_offset
LOCAL i
LOCAL nCount_i
LOCAL cId
LOCAL cDate_modified
LOCAL cV_module
nSuccess := 0
oRest := CreateObject("Chilkat.Rest")
nSuccess := oRest:Connect("your.site.domain", 443, 1, 1)
IF (nSuccess != 1)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
oRest:AddHeader("Cache-Control", "no-cache")
oRest:AddHeader("OAuth-Token", "<access_token>")
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
oJsonReq := CreateObject("Chilkat.JsonObject")
oJsonReq:UpdateString("filter[0].$or[0].name.$starts", "A")
oJsonReq:UpdateString("filter[0].$or[1].name.$starts", "b")
oJsonReq:UpdateNumber("max_num", "2")
oJsonReq:UpdateNumber("offset", "0")
oJsonReq:UpdateString("fields", "id")
oJsonReq:UpdateString("order_by", "date_entered")
oJsonReq:UpdateBool("favorites", 0)
oJsonReq:UpdateBool("my_items", 0)
// The JSON request body created by the above code:
// {
// "filter": [
// {
// "$or": [
// {
// "name": {
// "$starts": "A"
// }
// },
// {
// "name": {
// "$starts": "b"
// }
// }
// ]
// }
// ],
// "max_num": 2,
// "offset": 0,
// "fields": "id",
// "order_by": "date_entered",
// "favorites": false,
// "my_items": false
// }
oSbReq := CreateObject("Chilkat.StringBuilder")
oJsonReq:EmitSb(oSbReq)
oRest:AddHeader("Content-Type", "application/json")
oSbJson := CreateObject("Chilkat.StringBuilder")
nSuccess := oRest:FullRequestSb("POST", "/rest/v10/Accounts/filter", oSbReq, oSbJson)
IF (nSuccess != 1)
? oRest:LastErrorText
oRest:destroy()
oJsonReq:destroy()
oSbReq:destroy()
oSbJson:destroy()
RETURN
ENDIF
IF (oRest:ResponseStatusCode != 200)
? "Received error response code: " + Str(oRest:ResponseStatusCode)
? "Response body:"
? oSbJson:GetAsString()
oRest:destroy()
oJsonReq:destroy()
oSbReq:destroy()
oSbJson:destroy()
RETURN
ENDIF
oJson := CreateObject("Chilkat.JsonObject")
oJson:LoadSb(oSbJson)
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
nNext_offset := oJson:IntOf("next_offset")
i := 0
nCount_i := oJson:SizeOfArray("records")
DO WHILE i < nCount_i
oJson:I := i
cId := oJson:StringOf("records[i].id")
cDate_modified := oJson:StringOf("records[i].date_modified")
cV_module := oJson:StringOf("records[i]._module")
i := i + 1
ENDDO
// A sample JSON response body that is parsed by the above code:
// {
// "next_offset": 2,
// "records": [
// {
// "id": "f16760a4-3a52-f77d-1522-5703ca28925f",
// "date_modified": "2016-04-05T10:23:28-04:00",
// "_acl": {
// "fields": {}
// },
// "_module": "Accounts"
// },
// {
// "id": "ec409fbb-2b22-4f32-7fa1-5703caf78dc3",
// "date_modified": "2016-04-05T10:23:28-04:00",
// "_acl": {
// "fields": {}
// },
// "_module": "Accounts"
// }
// ]
// }
? "Example Completed."
oRest:destroy()
oJsonReq:destroy()
oSbReq:destroy()
oSbJson:destroy()
oJson:destroy()