You can't do that with scripted fields, mostly for performance reasons.
Instead, it is recommended to do these things before the documents get indexed in Elasticsearch.
It's possible to do this in your own application (before ingesting, doing a request to Elasticsearch and basically moving the script into your application).
However it makes sense to solve it within the Elastic stack. You can use an ingest pipeline with an enrich processor - use it to look up the fields you need and put them into your document - then you can use a script processor to execute your script based on the data pulled in from other documents.