-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WhereRaw for Dates in d365 #76
Comments
Anyone has the answer? |
Hey @Joost-Wolthuis, I ended up creating my own dummy client. Notice that is very laravely, but I hope you can figure it out public function getEntity(string $entity, array $filters = [], $count = 0)
{
$nextLink = null;
$responseValues = [];
do{
$headers = $this->getDefaultHeaders(); # Gets the auth token
$endpoint = $this->config->resource . '/data/'. $entity;
$top = $count ? '&$top=' . $count : '' ;
$queryString = '?$filter=1 eq 1 ';
$queryString .= implode(' ', $filters);
$endpoint .= $queryString . $top;
// Override if there is a nextLink which means it already got requested
$endpoint = $nextLink ?? $endpoint;
$response = Http::withHeaders($headers)->get($endpoint); # You can replace it with guzzle
$arrayResponse = $response->json();
array_push($responseValues, ...($arrayResponse['value'] ?? []));
}while($nextLink = $arrayResponse['@odata.nextLink'] ?? false);
return $responseValues;
}
# Usage
$config = (object) Config($this->apiConfigPath);
$client = new ApiClient($config);
$zuluStartDate = $this->getStartDate()->toIso8601ZuluString();
$zuluEndDate = $this->getEndDate()->toIso8601ZuluString();
$filters = [
"and RecordModifiedDateTime ge {$zuluStartDate}",
"and RecordModifiedDateTime lt {$zuluEndDate}",
];
$payload = $client->getEntity('YourEntity', $filters); Hope it helps |
I implemented internally a 'whereRaw()' method that simply takes a manually built string and adds it as a $filter. Might be of use? Basically you would just need to do something like
If appropriate i could create a pull request. |
As they are extending Laravel's Query Builder, why not use the |
Hi,
Thanks for this amazing library, however I'm having problems trying to filter a query using a date field in D365. They way this accepts is is
$filter=<date_field> lt 2021-01-12T14:21:02Z
. As you can see the date value is unescaped but the grammar always surrounds the value with single quotes if this is not a boolean.Is there any workaround or fix for this?
The text was updated successfully, but these errors were encountered: