Forge Viewer: getExternalIdMapping() to return only certain dbIds from certain externalIds

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]);
/*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.

Read more here: Source link