Skip to content

Commit 09cf628

Browse files
adding missing parameters, conversions to search api v2.0, updating readme
1 parent 4eb2ccc commit 09cf628

17 files changed

+907
-173
lines changed

.github/NEW_IN_V2.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ DynamicsWebApi v2 has been fully rewritten in TypeScript. The process of rewriti
44

55
### Microsoft Dataverse Search API
66
v2 brings the power of Search, Suggest and Autocomplete capabilities of Microsoft Dataverse Search API.
7+
`v2.3+` brings support for Dataverse Search API v2.0.
78

89
### `AbortController` and `AbortSignal` support (for Node.js 15+ and Browser)
910
Each request can now be aborted when it's no longer need to be completed via the `AbortController`.
@@ -20,6 +21,9 @@ Retrieve the org's CSDL $metadata document with a single call of `retrieveCsdlMe
2021
### `v2.1+` Microsoft Power Pages Support
2122
DynamicsWebApi now can be used in Micorosoft Power Pages website.
2223

24+
### `v2.3+` Background Operations Support
25+
DynamicsWebApi supports enabling of background operations for custom actions.
26+
2327
### NPM Package contents
2428
NPM package now includes a pre-bundled code of DynamicsWebApi to simplify a compilation process of the projects that depend on it. There are 4 separate bundles:
2529
- `dist/dynamics-web-api.js` - a Browser ready version (to use as a Dynamics 365 web resource) + it's minified version `.min.js` [IIFE].

.github/README.md

Lines changed: 82 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,92 +2161,98 @@ const isDeleted = await dynamicsWebApi.deleteRecord({
21612161
21622162
## Work with Dataverse Search API
21632163
2164-
**Important!** Currently only Search API 1.0 is supported. Search API 2.0 is coming with `v.2.3.0`.
2165-
If you must use 2.0, you could [use corresponding Actions](#execute-web-api-actions) for now. [more info](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/search/overview?tabs=sdk)
2164+
DynamicsWebApi can be used to call Dataverse Search API and utilize its powerful Query, Suggest and Autocomplete capabilities. Before using, I highly recommend to get familiar with it by reading an [official documentation](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/search/overview?tabs=webapi).
21662165
2167-
DynamicsWebApi can be used to call Dataverse Search API and utilize its powerful Search, Suggest and Autocomplete capabilities. Before using, I highly recommend to get familiar with it by reading an [official documentation](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/search/legacy).
2166+
**Important!** This documentation is based on the Dataverse Search API v2.0. If you would like to find documentation about v1.0, please check [here](https://github.com/AleksandrRogov/DynamicsWebApi/blob/v2.2.1/.github/README.md#work-with-dataverse-search-api). But keep in mind, that some properties in the request and response objects are marked as deprecated to encourage usage of the v2.0 properties. Deprecated properties will be removed in the next major version.
21682167
2169-
To set Search API version use: `new DynamicsWebApi({ searchApi: { version: "1.0" }})`.
2168+
To set a Search API version use: `new DynamicsWebApi({ searchApi: { version: "2.0" }})`.
21702169
2171-
Search, Suggest and Autocomplete requests have a common property `query`. This is the main property that configures a relevance search request.
2170+
All functions: Query, Suggest and Autocomplete, - can be called with a single `string` parameter "a search term". But to utilize the full power of the relevance search use a common property `query` that is available in all 3 requests.
21722171
2173-
All functions can also be called with a single parameter `term` which is of type `string`.
2172+
_Examples below follow Microsoft's official documenation._
21742173
2175-
Examples below follow Microsoft official documenation.
2174+
**Note!** All request properties are `camelCase`, even though in Dataverse Search API v2.0 they are lowercase.
21762175
2177-
### Search
2176+
### Query
21782177
2179-
The following table describes all parameters for a `search` request:
2178+
The following table describes all parameters for a `query` request:
21802179
21812180
Property Name | Type | Description
21822181
------------ | ------------- | -------------
21832182
search | `string` | **Required**. The search parameter value contains the term to be searched for and has a 100-character limit.
2184-
entities | `string[]` | The default table list searches across all Dataverse search–configured tables and columns. The default list is configured by your administrator when Dataverse search is enabled.
2183+
count | `boolean` | Specify true to return the total record count; otherwise false. The default is **false**.
2184+
entities | `string`, `string[]` or `SearchEntity[]` | Limits the scope of search to a subset of tables. The default set is configured by your administrator when Dataverse search is enabled.
21852185
facets | `string[]` | Facets support the ability to drill down into data results after they've been retrieved.
2186-
filter | `string` | Filters are applied while searching data and are specified in standard OData syntax.
2187-
orderBy | `string[]` | A list of comma-separated clauses where each clause consists of a column name followed by 'asc' (ascending, which is the default) or 'desc' (descending). This list specifies how to order the results in order of precedence.
2188-
returnTotalRecordCount | `boolean` | Specify true to return the total record count; otherwise false. The default is **false**.
2189-
searchMode | `string` | Specifies whether **any** or **all** the search terms must be matched to count the document as a match. The default is '**any**'.
2190-
searchType | `string` | The search type specifies the syntax of a search query. Using '**simple**' selects simple query syntax and '**full**' selects Lucene query syntax. The default is '**simple**'.
2186+
filter | `string` | Limits the scope of the search results returned.
2187+
options | `string` or `SearchOptions` | Options are settings configured to search a search term.
2188+
orderBy | `string[]` | Specifies how to order the results in order of precedence.
21912189
skip | `number` | Specifies the number of search results to skip.
21922190
top | `number` | Specifies the number of search results to retrieve. The default is **50**, and the maximum value is **100**.
21932191
2192+
**SearchEntity**
2193+
2194+
Use this type to compose the array of tables to pass to the entities parameter.
2195+
2196+
Property Name | Type | Description
2197+
------------ | ------------- | -------------
2198+
name | `string` | **Required**. Logical name of the table. Specifies scope of the query.
2199+
selectColumns | `string[]` | Optional. List of columns that needs to be projected when table documents are returned in response. If empty, only the table primary name is returned.
2200+
searchColumns | `string[]` | Optional. List of columns to scope the query on. If empty, only the table primary name is searched on.
2201+
filter | `string` | Optional. Filters applied on the entity.
2202+
2203+
**SearchOptions**
2204+
2205+
Options are settings configured to search a search term.
2206+
2207+
Property Name | Type | Description
2208+
------------ | ------------- | -------------
2209+
bestEffortSearchEnabled | `boolean` | Enables intelligent query workflow to return probable set of results if no good matches are found for the search request terms.
2210+
groupRankingEnabled | `boolean` | When specified as all the search terms must be matched in order to consider the document as a match. Setting its value to any defaults to matching any word in the search term.
2211+
queryType | `string` | Query Type. Values can be 'simple' or 'lucene'.
2212+
searchMode | `string` | Enable ranking of results in the response optimized for display in search results pages where results are grouped by table. Values can be 'any' or 'all'.
2213+
21942214
**Examples:**
21952215
21962216
```ts
2197-
let result = await dynamicsWebApi.search({
2217+
let result = await dynamicsWebApi.query({
21982218
query: {
21992219
search: "<search term>"
22002220
}
22012221
});
22022222

22032223
//the same as:
2204-
result = await dynamicsWebApi.search("<search term>");
2224+
result = await dynamicsWebApi.query("<search term>");
22052225
```
22062226
22072227
```ts
2208-
const result = await dynamicsWebApi.search({
2209-
query: {
2210-
search: "maria",
2211-
facets: [
2212-
"@search.entityname,count:100",
2213-
"account.primarycontactid,count:100",
2214-
"ownerid,count:100",
2215-
"modifiedon,values:2019-04-27T00:00:00|2020-03-27T00:00:00|2020-04-20T00:00:00|2020-04-27T00:00:00",
2216-
"createdon,values:2019-04-27T00:00:00|2020-03-27T00:00:00|2020-04-20T00:00:00|2020-04-27T00:00:00"
2217-
]
2218-
}
2219-
});
2220-
```
2228+
//more complex example (from Microsoft's documentation)
22212229

2222-
```ts
2223-
const result = await dynamicsWebApi.search({
2224-
query: {
2225-
search: "maria",
2226-
filter: "account:modifiedon ge 2020-04-27T00:00:00," +
2227-
"activities: regardingobjecttypecode eq 'account', annotation:objecttypecode eq 'account'," +
2228-
"incident: (prioritycode eq 1 or prioritycode eq 2)"
2229-
}
2230+
const result = await dynamicsWebApi.query({
2231+
search: "Contoso",
2232+
skip: 0,
2233+
top: 7,
2234+
entities: [{
2235+
name: "account",
2236+
selectColumns: ["name", "createdon"],
2237+
searchColumns: ["name"],
2238+
filter: "statecode eq 0"
2239+
}, {
2240+
name: "contact",
2241+
selectColumns: ["fullname", "createdon"],
2242+
searchColumns: ["fullname"],
2243+
filter: "statecode eq 0"
2244+
}],
2245+
orderBy: ["createdon desc"],
2246+
filter: "createdon gt 2022-08-15",
2247+
count: true
22302248
});
2231-
```
22322249

2233-
```ts
2234-
const result = await dynamicsWebApi.search({
2235-
query: {
2236-
search: "maria",
2237-
facets: [
2238-
"@search.entityname,count:100",
2239-
"account.primarycontactid,count:100",
2240-
"ownerid,count:100",
2241-
"modifiedon,values:2019-04-27T00:00:00|2020-03-27T00:00:00|2020-04-20T00:00:00|2020-04-27T00:00:00",
2242-
"createdon,values:2019-04-27T00:00:00|2020-03-27T00:00:00|2020-04-20T00:00:00|2020-04-27T00:00:00"
2243-
]
2244-
}
2245-
});
2250+
//result:
2251+
const error = result.Error;
2252+
const value = result.Value;
22462253

2247-
const firstHit = result.value[0];
2248-
const firstHitScore = firstHit["@search.score"];
2249-
const firstSearchEntityName = result.facets["@search.entityname"][0].Value;
2254+
const firstItemId = value[0].Id;
2255+
const firstItemEntityName = value[0].EntityName;
22502256
```
22512257
22522258
### Suggest
@@ -2255,12 +2261,20 @@ The following table describes all parameters for a `suggest` request:
22552261
22562262
Property Name | Type | Description
22572263
------------ | ------------- | -------------
2258-
search | `string` | **Required**. The search parameter value contains the term to be searched for and has a 3-character min limit and max 100-character limit.
2259-
entities | `string[]` | The default table list searches across all Dataverse search–configured tables and columns. The default list is configured by your administrator when Dataverse search is enabled.
2264+
search | `string` | **Required**. The text to search with. Search term must be at least three characters long and has a 100 character limit.
2265+
entities | `string`, `string[]` or `SearchEntity[]` | Limits the scope of search to a subset of tables. The default set is configured by your administrator when Dataverse search is enabled.
2266+
filter | `string` | Limits the scope of the search results returned.
2267+
fuzzy | `boolean` | Use fuzzy search to aid with misspellings. The default is false.
2268+
options | `string` or `SuggestionOptions` | Options are settings configured to search a search term.
22602269
orderBy | `string[]` | A list of comma-separated clauses where each clause consists of a column name followed by 'asc' (ascending, which is the default) or 'desc' (descending). This list specifies how to order the results in order of precedence.
2261-
filter | `string` | Filters are applied while searching data and are specified in standard OData syntax.
22622270
top | `number` | Number of suggestions to retrieve. The default is **5**.
2263-
useFuzzy | `boolean` | Use fuzzy search to aid with misspellings. The default is false.
2271+
2272+
**SuggestionOptions**
2273+
Options are settings configured to search a search term.
2274+
2275+
Property Name | Type | Description
2276+
------------ | ------------- | -------------
2277+
advancedSuggestEnabled | `boolean` | Enables advanced suggestions for the search query. The default is false.
22642278
22652279
**Examples:**
22662280
@@ -2274,8 +2288,9 @@ let result = await dynamicsWebApi.suggest({
22742288
//the same as:
22752289
result = await dynamicsWebApi.suggest("mar");
22762290

2277-
const firstText = result.value[0].text;
2278-
const firstDocument = result.value[0].document;
2291+
const firstText = result.Value[0].Text;
2292+
const firstDocument = result.Value[0].Document;
2293+
const error = result.Error;
22792294
```
22802295
22812296
```ts
@@ -2294,10 +2309,10 @@ The following table describes all parameters for an `autocomplete` request:
22942309
22952310
Property Name | Type | Description
22962311
------------ | ------------- | -------------
2297-
search | `string` | **Required**. The search parameter value contains the term to be searched for and has a 100-character limit.
2298-
entities | `string[]` | The default table list searches across all Dataverse search–configured tables and columns. The default list is configured by your administrator when Dataverse search is enabled.
2299-
filter | `string` | Filters are applied while searching data and are specified in standard OData syntax.
2300-
useFuzzy | `boolean` | Use fuzzy search to aid with misspellings. The default is false.
2312+
search | `string` | **Required**. Search term must be at least one character long and has a 100 character limit.
2313+
entities | `string`, `string[]` or `SearchEntity[]` | Limits the scope of search to a subset of tables. The default set is configured by your administrator when Dataverse search is enabled.
2314+
filter | `string` | Limits the scope of the search results returned.
2315+
fuzzy | `boolean` | Use fuzzy search to aid with misspellings. The default is false.
23012316
23022317
**Examples:**
23032318
@@ -2311,7 +2326,8 @@ let result = await dynamicsWebApi.autocomplete({
23112326
//the same as:
23122327
result = await dynamicsWebApi.autocomplete("mar");
23132328

2314-
const value = result.value;
2329+
const error = result.Error;
2330+
const value = result.Value;
23152331
```
23162332
23172333
```ts

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ As well as Microsoft Dynamics 365 CE (online), Microsoft Dynamics 365 CE (on-pre
2121
- **Abort Signal and Abort Controller** (Browser and Node.js 15+). Abort requests when they are no longer need to be completed.
2222
- **Node.js and a Browser** support.
2323
- **Proxy Configuration** support.
24-
- **Background Operations** support.
24+
- **Background Operations** support. `v2.3.0+`
2525
- Works with **Microsoft Power Pages** (aka Microsoft Portal). `v2.1.0+`
2626

2727
Browser-compiled script and type definitions can be found in a v2 [dist](https://github.com/AleksandrRogov/DynamicsWebApi/tree/v2/dist) folder.

dist/browser/esm/dynamics-web-api.js

Lines changed: 85 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)