# Mapping links in imported content into Fibery links/references

**URL:** <https://community.fibery.io/t/mapping-links-in-imported-content-into-fibery-links-references/3213>\
**Category:** Get Help\
**Created:** [August 28, 2022, 1:24am UTC](https://community.fibery.io/t/mapping-links-in-imported-content-into-fibery-links-references/3213 "2022-08-28T01:24:04Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [August 29, 2022, 10:22am UTC](https://community.fibery.io/t/mapping-links-in-imported-content-into-fibery-links-references/3213/4 "2022-08-29T10:22:36Z")

</div>

Here’s what I would suggest, with the Obsidian import as an example:

Import the various text files (as is) into a Docs DB as you suggest.

Write an automation script something like this:

```auto
const fibery = context.getService('fibery');

//get the whole schema
const schema = await fibery.getSchema();
//get the entity type
const typeName = args.currentEntities[0].type;
// filter the schema for the specific type and get the spacename and database id
const namespace = schema['typeObjects'].filter((obj) => obj.name == typeName)[0]['nameParts']['namespace'];
const databaseID = schema['typeObjects'].filter((obj) => obj.name == typeName)[0]['id']
//get all documents in the database (assumes DB is called Doc)
const allDocs = await fibery.graphql(namespace, "{ findDocs{ id, name }}");

//create a lookup table that matches entity names to 'mentions'
//the mentions are constructed from the database id and the entity id 
const lookupTable = allDocs['data']['findDocs'].reduce((obj, item) => (obj[item.name] = "[[#^" + databaseID + "/" + item.id + "]]", obj), {});

//for each entity
for (const entity of args.currentEntities) {
    //get the contents of the Description field (change to suit)
    const textToUpdate = await fibery.getDocumentContent(entity['Description']['Secret']);
    //check for not null doc
    if (textToUpdate !== null) {
        //look for substrings that match the Obsidian formatting (as exported from Fibery)
        //Note: Fibery escapes the [and] characters with backspaces, so we are looking for
        // \[\[Title of obsidian document\]\]
        //and the regex needs to escape these characters!
        const replacementText = textToUpdate.replace(/\\\[\\\[[^\\\]]+\\\]\\\]/g, (match, key) => {
            //trim to get the title to be looked up (remove the \[\[and \]\] bits )
            const title = match.replace(/\\\[\\\[|\\\]\\\]/g, '');
            //if a match exists in the lookupTable, then replace
            return lookupTable[title] !== undefined
                ? lookupTable[title]
                : match;
        });
        //write the resultant text back to the Description field
        await fibery.setDocumentContent(entity['Description']['Secret'], replacementText)
    }
};

```

I hope the comments explain what it is doing.

I suggest running the script on a couple of sample Obsidian docs to check it works, then doing all your Obsidian docs.

Then you will probably have to experiment a bit to get the right regex for Quip and Notion, but hopefully you can figure these out.  
Adding some console logging will no doubt make it easier to debug 😉  
If not, come back to the community and we’ll help 🙂

You might want to read this topic to see why the lookupTable is formatted the way it is:

> [@Is it possible to mention in comment or doc via script or API?](https://community.fibery.io/t/is-it-possible-to-mention-in-comment-or-doc-via-script-or-api/3203/4):
>
> Do you mean that you want to add a comment (that mentions a user) to an entity? In general, the contents of a comment can be described using markdown, and mentioning a user is done using the following format: [[#@xxxxxx/yyyyyy]] where xxxxxx is the ID of the user database and yyyyyy is the ID of the user. I presume that you are comfortable with using scripting to create/update comments.

Entity mentions work similarly to comments, but use [[#^xxxxxx/yyyyyy]] instead.

---

_[View the full topic](https://community.fibery.io/t/mapping-links-in-imported-content-into-fibery-links-references/3213)._
