Allow Rules/Formula Involving Rich-Text Fields

Yeah, i realized afterwards that might be an issue. When you delete the contents it doesn’t actually delete the attached document that is now non-null but empty. Here is an updated script to handle that case.

// Developer reference is at api.fibery.io/#action-buttons

// Fibery API is used to retrieve and update entities
const fibery = context.getService('fibery');

// affected entities are stored in args.currentEntities;
// to support batch actions they always come in an array
for (const entity of args.currentEntities) {

    // the rich text field is a document, which requires a special id to get access to
    // In this case, the rich text field is "Description", so we request that field be included
    const entityWithExtraFields = await fibery.getEntityById(entity.type, entity.id, ['Description']);

    // as long as we have the rich text field looking valid, let's do something with it
    if (entityWithExtraFields['Description']) {
        // just saving a shorter reference to it
        const dsc = entityWithExtraFields['Description'];

        // get the rich text field contents as markdown (supports md, html, and json)
        const doc = await fibery.getDocumentContent(dsc.secret, 'md');

        // now we can search the rich text for whatever we are looking for
        // In this case, lets just see if the doc is non-null and non-empty, 
        // then update a checkbox
        const docExists = ((doc !== null) && (doc !== ''));
        await fibery.updateEntity(entity.type, entity.id, {
            'Description Exists': docExists
        });
    }
}

Edit: if you add a console.log(doc) in there just after you get the doc contents, you could see the output in your browser’s dev console, then adjust the logic to handle any special cases. For example, you could look at the length of the document, look for specific terms, etc.

4 Likes