Submit a request
Submit a request

Building Your Own Custom Workflow - a Solution Using Tags

This article outlines how to support custom workflows for Items and Activities using Tags in Author API.

In the article Restricting Items and Activities access using Author API, we outlined how the filter.restricted object of item_list and activity_list allows you to filter out the list of Items and Activities you would want your users to access in your application. Using these filters, we can support custom workflows within your application.

Handling simple workflows

We will start off by showing how to support a simple workflow. In this simple workflow, the author creates an Item or Activity and marks it as draft until they want to submit it to a reviewer. The reviewer then either approves it, or marks it for rework. If it is marked as requiring rework, the author reworks the Item or Activity and submits again for review. This cycle is repeated until it is approved by the reviewer.

Using the filter.restricted.current_user initialization flag, you can restrict the list of Items in the item_list and Activities in the activity_list for the authors to only the Items and Activities created by them. This flag overrides the created_by option and will not display any Items or Activities created by any other author.

Figure 1: A simple workflow between authors and reviewers.

We will create a Tag of type “Workflow” having the name values of “Draft”“Submit_For_Review”“Rework_Required”“Rework_Draft” and “Approved” for each of the stages in the simple workflow. At any given stage of the simple workflow, Items or Activities will have exactly one name value for the Tag type “Workflow” as given below.

Figure 2: The same simple workflow with the associated Tags for each phase.

You can bind into the Author API’s save event to make sure Items are created with the Workflow Tag type by default with the name Draft. For example:

var myFunction = function () {
    var itemTags = authorApp.getItemTags();

    if (itemTags.filter(e => e.type === 'Workflow').length == 0) {
        itemTags.push({name: 'Draft', type: 'Workflow'});
        authorApp.setItemTags(itemTags);
    }
}

authorApp.on('save', myFunction);

Your application can provide the reviewer access to all Items or Activities submitted for review by the filter configuration of Author API based on Tags. For example:

'filter' => array(
    'restricted' => array(
        'tags' => array(
            'either' => array(
                array(
                    'type' => 'Workflow',
                    'name' =>'Submit_for_Review'
                )
            )
        )
    )
)

The filter can be based on users instead of Tags, to provide access to Items and Activities created by specific users. For example:

'filter' => array(
    'restricted' => array(
        'tags' => array(
            'either' => array(
                array(
                    'type' => 'Workflow',
                    'name' =>'Submit_for_Review'
                )
            )
        ),
        'created_by' => array(
            'user1','user2'
        )
    )
)

To move an Item or Activity from the Draft stage to “Ready for Review”, you could update the Tag Name for the Workflow Tag Type. Before you do this, you need to set the allow_filtered_tags_overwrite flag in the restricted object of the init option to true. For example:

var myFunction = function () {
    var itemTags = authorApp.getItemTags();

    for (i = 0; i < itemTags.length; i++) {
        if (itemTags[i].type === 'Workflow'){
            itemTags[i].name = 'Approved';
        }

        authorApp.setItemTags(itemTags);
        authorApp.save();
    }
}

Handling complex workflows

For an editorial type workflow where an Item or Activity can have more than one stage associated, you can use a combination of “all”, “either” and “none” Tag filtering options to restrict the Items or Activities available in the list.

Was this article helpful?
0 out of 0 found this helpful

Did you arrive here by accident? If so, learn more about Learnosity by clicking here.