this.viewer.model.getExternalIdMapping(data => console.log(data))
This particular line gets everything. But I only need the dbIds of certain externalIds. How can I do that?
A few ways depending on what exactly you need. Here's what I've done.
function getDbIdFromExternalId(externalIds) {
return new Promise((resolve) => {
viewer.model.getExternalIdMapping((d) => {
//console.log("getDbIdFromExternalId Executed");
let responseArr = [];
externalIds.forEach(externalId => {
if(d[externalId]) responseArr.push([d[externalId], externalId]);
});
resolve(responseArr);
});
});
}
/*Your external IDs in here*/
var externalIds = ['23287','23292','23291'];
/*response is set here*/
var response = await getDbIdFromExternalId(externalIds);
Expected value of response (with my autocad viewer): [[39675,"23292"],[39674,"23291"]]
That way you can see the pair. Notice I threw in a value that didn't map to anything, so the array was only populated with what it found.
Another option would be to implement your own user function and calling the getExternalIdMapping method of the property database that can actually be filtered for specific external IDs:
function mapMyExternalIds(model, externalIds) {
const filter = {};
for (const externalId of externalIds) {
filter[externalId] = true;
}
return model.getPropertyDb().executeUserFunction(function userFunction(pdb, filter) {
return pdb.getExternalIdMapping(filter);
}, filter);
}
Then you can use it like so:
mapMyExternalIds(NOP_VIEWER.model, ["6949fe39-3e9a-4d4d-b7fe-71339c615138-00022318"])
.then(map => console.log(map))
.catch(err => console.error(err));