AutoIt
AutoIt
SugarCRM Filtering Records
See more SugarCRM Examples
Export records and filter.Chilkat AutoIt Downloads
Local $bSuccess = False
$oRest = ObjCreate("Chilkat.Rest")
$bSuccess = $oRest.Connect("your.site.domain",443,True,True)
If ($bSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
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 = ObjCreate("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",False)
$oJsonReq.UpdateBool("my_items",False)
; 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 = ObjCreate("Chilkat.StringBuilder")
$oJsonReq.EmitSb($oSbReq)
$oRest.AddHeader("Content-Type","application/json")
$oSbJson = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oRest.FullRequestSb("POST","/rest/v10/Accounts/filter",$oSbReq,$oSbJson)
If ($bSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
If ($oRest.ResponseStatusCode <> 200) Then
ConsoleWrite("Received error response code: " & $oRest.ResponseStatusCode & @CRLF)
ConsoleWrite("Response body:" & @CRLF)
ConsoleWrite($oSbJson.GetAsString() & @CRLF)
Exit
EndIf
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.LoadSb($oSbJson)
; The following code parses the JSON response.
; A sample JSON response is shown below the sample code.
Local $iNext_offset
Local $i
Local $iCount_i
Local $sId
Local $sDate_modified
Local $sV_module
$iNext_offset = $oJson.IntOf("next_offset")
$i = 0
$iCount_i = $oJson.SizeOfArray("records")
While $i < $iCount_i
$oJson.I = $i
$sId = $oJson.StringOf("records[i].id")
$sDate_modified = $oJson.StringOf("records[i].date_modified")
$sV_module = $oJson.StringOf("records[i]._module")
$i = $i + 1
Wend
; 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"
; }
; ]
; }
ConsoleWrite("Example Completed." & @CRLF)