Checklist Pro - Programmatic Checklist Creation
In the “How Does Checklist Pro Do It?” blogpost, we talk about how Checklist Pro creates a Checklist. We discuss two options:
“Programmatically” - through a Checklist Pro API call.
“Conditionally” – when someone browses to a record where a checklist is defined.
Since the above-mentioned blogpost covers the “Conditionally” created option, this blogpost will cover the “Programmatic” option.
We will also discuss why you may want to do one vs the other.
In prior examples, we created a “Cascading” checklist that would appear conditionally on an incident table if the incident was in a “New” or “In-Progress” state and if the category was “Inquiry / Help” and the subcategory was “Antivirus”. Under those conditions, if you navigated to a record where those conditions were true, then Checklist Pro would create a checklist (if one did not already exist).
However, if we wanted to simply create that “Cascading” checklist on an incident (any incident we wanted), then we would use the Checklist Pro API library to programmatically create our checklist.
Creating a Checklist Programmatically
In this example, our “Cascading” checklist is in a Checklist Configuration record called “INCIDENT – Cascading Checklist”.
In this Fix Script, we’ll create the checklist, adding it to some open incident record.
WARNING – if there is already a checklist associated with a particular record, this API call will add an additional checklist, so you may want to add logic to check if there is an existing checklist. See the modified code example below:
Now, when we visit the incident that the checklist was added to, we see the checklist there. We forcefully created the checklist on our desired record even though it does not have “conditions” matching that which would be required for it to be created by the Checklist Pro engine.
So, what are the advantages and disadvantages of creating checklists “Conditionally” (Checklist Pro Engine) and “Programmatically” (Checklist Pro API)?
A common situation for checklist creation is that you need to be sure the checklist exists even if nobody has opened the record where you want the checklist to appear. That could be the case for a checklist on an approval request or some task from a workflow.
Creating a checklist programmatically (via the API), would guarantee the checklist is on the record. If your checklist had “required” items that were assumed to be completed later in the workflow (for processing), then programmatically creating the checklist items may be the way to go. This would prevent someone from just closing a task (from the list view) or approving a request (again, from the list view without ever actually opening the record) and then not having the checklist exist because the record was never opened.