Here's how you can access the native API
and using that you can access Historian
records for a particular asset
const id = transaction.assetId;
const nativeSupport = transaction.nativeSupport;
const nativeKey = getNativeAPI().createCompositeKey('Asset:systest.transactions.SimpleStringAsset', [id]);
const iterator = await getNativeAPI().getHistoryForKey(nativeKey);
let results = [];
let res = {done : false};
while (!res.done) {
res = await iterator.next();
if (res && res.value && res.value.value) {
let val = res.value.value.toString('utf8');
if (val.length > 0) {
results.push(JSON.parse(val));
}
}
if (res && res.done) {
try {
iterator.close();
}
catch (err) {
}
}
}
For more information, please check out this url: https://hyperledger.github.io/composer/latest/reference/js_scripts