I have an options field which is sourced from an external json file using the following code.
$nsbooks_url = 'https://mysite.com/myjson.json';
$preoptions = json_decode(file_get_contents($nsbooks_url), TRUE);
$options = array_column($preoptions, 'Document Number');
\Drupal::cache()->set('nsbooks', $options);
The JSON file contains these lines.
[{
"custid": "88149",
"recordType": "salesorder",
"Document Number": "SO7878"
}, {
"custid": "89757",
"recordType": "salesorder",
"Document Number": "SO1226"
}]
In the webform, I have another field where the user enters their customer ID number. (custid in the JSON file.)
What I am trying to do is filter the JSON file so that only document numbers that match that customer ID number are shown as an option. How can I achieve this?