Authors:
Cameron Johns, Cille Schliebitz, Anita Gu
Changed on:
3 Feb 2025
This lesson focuses on fetching data within a custom form field using the
`useQuery`
`useQuery`
`useAuth`
`useQuery`
`searchVirtualInventory`
`useQuery`
`useQuery`
`productRef`
`locationRef`
`lat`
`lng`
`useAuth`
To retrieve a list of locations with stock close by (using the SearchVirtualInventory query), you will need to perform the following steps:
`useQuery`
First, define a structure for the SearchVirtualInventory query result nodes:
`interface SVINode {`
` location: { name: string; ref: string };`
` virtualPositions: Array;`
`}`
Next, define a structure for SearchVirtualInventory results:
`interface SVIResult {`
` searchVirtualInventory: Connection;`
`}`
Store the query in a string constant:
1const searchVirtualInventoryQuery = `query availability($productRef: String!, $locationRef: String!, $lat: Float!, $lng: Float!) {
2 searchVirtualInventory(
3 virtualCatalogue: { ref: "VC:ATS:CC:1" },
4 productQuantities: [{ productRef: $productRef, quantity: 1 }],
5 excludedLocationRefs: [$locationRef],
6 orderByProximity: { longitude: $lng, latitude: $lat }
7 ) {
8 edges {
9 node {
10 location { ref name }
11 virtualPositions { quantity }
12 }
13 }
14 }
15 }`;
Language: plain_text
Name: searchVirtualInventoryQuery
Description:
This string constant stores the GraphQL query used to fetch virtual inventory data. The query retrieves a list of locations that stock a specific product, excluding the current location, and orders the results by proximity to a given latitude and longitude. It takes
`productRef`
`locationRef`
`lat`
`lng`
Refer to the video below to complete the remaining steps:
`useQuery`
Each Form has context information about the entity or entities being updated. This form is generated based on a User Action defined a Product Ruleset within the Product Catalogue workflow, and therefore has context of the Product entity.
`productRef`
`entityContext`
`FormFieldProps`
`locationRef`
`lat`
`lng`
`useAuth`
This video explains how to fetch data from a component using a useQuery hook
Now that our query is returning data, we need to present a list for the user to select a specific location.
Watch the following video to complete to steps below:
`FormControlLabel`
`onChange`
`location`
`useEffect`
`location`
This video explains how to make use of query data obtained from the component