Module: job_template

Copyright 2020 Parsable, Inc
API address: /api/job_templates
Functionality for Job Templates. A Job Template is the template for a type of job or process or procedure, from which Job instances are created.

ModuleServicesData typesConstants
job_templateJobTemplateService
ForceAcquireResponse
IndexOpts
JobTemplate
JobTemplateLockFailed
JobTemplateModular
JobTemplateParams
JobTemplateStats
JobTemplateStatus
TemplateDraft
TemplateFetchResult
TemplateHistoryResult
TemplateInfo
TemplateOrder
TemplateOrderBy
TemplatePublicVersion
TemplateQueryResult
TemplateSelectOpts
TemplateTag
TemplateTextSearch
TemplateType
TemplateWhereOpts

Enumerations

Enumeration: TemplateType


Job0
Issue1

Enumeration: JobTemplateStatus

Status of a job template

PUBLISHED1
UNPUBLISHED2
IN_REVIEW3

Enumeration: TemplateOrderBy


TITLE1
AUTHORED_AT2
LAST_MODIFIED_AT3
TYPE4

Data structures

Struct: IndexOpts

KeyFieldTypeDescriptionRequirednessDefault value
1showUnpublishedbooldefaulttrue
2showArchivedbooldefaulttrue

Options for listing job templates

Struct: JobTemplateParams

KeyFieldTypeDescriptionRequirednessDefault value
1titlestringName of the job template. This is required on creation. optional
2descripstringDescription of the job template optional
3metadataEntrylist<metadata.MetadataEntry>Metadata for the job template optional
4typTemplateTypeTemplate type, cannot be updated optional

Mutable parts of the job template

Exception: JobTemplateLockFailed

KeyFieldTypeDescriptionRequirednessDefault value
1previousLockJobTemplateLockconflicting lock details default
2messagestringdefault

Response type for acquireLock

Struct: ForceAcquireResponse

KeyFieldTypeDescriptionRequirednessDefault value
1previousLockJobTemplateLockbroken lock details (may be missing) optional
2currentLockJobTemplateLocknew lock details default

Response type for forceAcquireLock

Struct: TemplateTag

KeyFieldTypeDescriptionRequirednessDefault value
1tagIdstringId of the associated tag. The tag must belong to the same team as the template. default
2namestringName of the tag. This is a READ-ONLY field, will be ignored on writes optional
3commentstringOptional comment on the association between the tag and template optional

Defines a relationship between a tag and a template. tagId is the only required field. The server will populate all three fields.

Struct: JobTemplate

KeyFieldTypeDescriptionRequirednessDefault value
1idstringdefault
2titlestringThe name of a Job Template default
3versioni32Only increments when update is called. default
4publicVersioni32Increment logic for publicVersion:

Normal team flow:
1. A new job template is created with create, initially publicVersion=0 and status=Unpublished.
2. publicVersion increments by 1 from latest published publicVersion when publish is called, and status=Published.
3. When a new edit is made with update on either published or unpublished job template, a new entry is created with publicVersion=0 and status=Unpublished.
4. Repeat from step 2) or 3).

Review team flow:
1. A new job template is created with create, initially publicVersion=0 and status=Unpublished.
2. publicVersion increments by 1 from max publicVersion when beginReview is called, and status=InReview. publicVersion does not change if this internalVersion has already been reviewed before, i.e., publicVersion != 0.
3. endReview must be called next to close review, making status=Unpublished.
4. A specific publicVersion must be used to call publishVersion and make status=Published.
5. When a new edit is made with update on either published or unpublished job template, a new entry is created with publicVersion=0 and status=Unpublished.
6. Repeat from step 2) or 5).
default
5stepGroupstep.BaseStepThe top step group of the job template's step hierarchy default
6statusstringStatus of the job template default
7descripstringDetails about the job default
8teamteam.Teamdefault
9metadataEntrylist<metadata.MetadataEntry>optional
10UNSUPPORTEDdocumentEmailAddressstringUNSUPPORTED Email address for this particular job template default
11documentslist<document.Document>List of documents for this job template default
12archivedAti64Unix timestamp of when the job template was archived. 0 means the job template is not archived. An archived job template cannot be edited or used to create a job default
13lastAuthorstringThe id of the last user to modify this template version default
14systemboolSystem template, cannot be modified default
15lockedJobTemplateLockInternal authoring lock optional
16lastAuthoredAti64Unix timestamp of authored time for this edit default
17publishedAti64Unix timestamp of publish time for this edit. 0 if not published default
18lastPublishedAti64DEPRECATED Bumps up on Create/Publish/InReview/Reject, 0 if no such event has occurred. Note that this field is wrongly named. default
19templateTagslist<TemplateTag>List of tags default
20metadataByIdmap<string, metadata.MetadataEntry>Replaces metadataEntry default
21publishedVersioni32Only increments when publish or publishVersion is called. Is the same as publicVersion for normal teams, and only increments on publish for review teams. Is 0 for all job templates with status!=Published. default
22typTemplateTypedefault
23lastPublishedBystringThe id of the last user to publish this template optional
24readOnlybooloptional
25globalTemplatebooloptional
26localTemplateboolIf the current template is a Local instance of a Global template. I.e. true if sourceTemplateId, sourceTemplateVersion are populated. optional
27archiveDisabledbooloptional

Fields of a JobTemplate

Struct: JobTemplateStats

KeyFieldTypeDescriptionRequirednessDefault value
1completedJobsi32default
2activeJobsi32default

Struct: TemplateDraft

KeyFieldTypeDescriptionRequirednessDefault value
1versioni32default
2authoredAti64default
3authorIdstringdefault
4displaybooldefault
5publicVersioni32default
6statusJobTemplateStatusdefault
7publishedVersioni32default

Struct: JobTemplateModular

KeyFieldTypeDescriptionRequirednessDefault value
1idstringTemplate UUID default
2internalVersioni32See version in JobTemplate default
3publicVersioni32See publicVersion in JobTemplate default
4titlestringdefault
5descripstringDescription default
6statusJobTemplateStatusdefault
7stepGroupIdstringdefault
8teamIdstringdefault
9UNSUPPORTEDdocumentEmailAddressstringUNSUPPORTED Email address for this particular job template default
10lastAuthoredAti64authored time for this edit default
11publishedAti64published time for this edit, 0 if not published default
13archivedAti64archive time, 0 means the job template is not archived default
14lastAuthorIdstringdefault
15systembooldefault
16metadataEntrylist<metadata.MetadataEntry>default
17metadataByIdmap<string, metadata.MetadataEntry>default
18publishedVersioni32See publishedVersion in JobTemplate default
19typTemplateTypedefault
20lockedJobTemplateLockInternal authoring lock optional
21publishedByIdstringThe id of the last user to publish this template optional
101teamteam.TeamModularoptional
102rootHeadersgroup_headers.StepGroupHeadersoptional
103stepGroupstep.BaseStepoptional
104documentslist<document.Document>optional
105lastPublishedAti64DEPRECATED Bumps up on Create/Publish/InReview/Reject, 0 if no such event has occurred. Note that this field is wrongly named. optional
106lastAuthoruser.Useroptional
107statsJobTemplateStatsoptional
108templateTagslist<TemplateTag>optional
109draftslist<TemplateDraft>All drafts since and including last published optional
110lastPublishedVersioni32last published version for this template. 0 if not published optional
111lastPublishTimei64Bumps up on Publish, 0 if never pubished. (fixed version of lastPublishedAt) optional
112lastModifiedAti64Bumps up on edit, status change, archive optional
113attributeslist<abac.AbacAttribute>optional
115referencesmap<reference.RefSource, set<string>>optional
120plannedDataSheetIdsmap<string, string>Map of data sheet set id -> data sheet id picked during job planning This is only valid if the data sheet set ids are contained in references above optional
121snapshottedDataSheetValuesmap<string, data_sheet.DataSheetValue>Map of data sheet set definition id -> data sheet value snapshotted at/after job start This is only valid if the data sheet set definition ids are contained in references above optional
122originalAuthoruser.UserModularoptional
123reviewFlowRequiredboolIf true, this template requires the review flow. This is only populated by JobTemplateService.Fetch optional
124lastPublishedByuser.Useroptional
125readOnlybooloptional
126globalTemplatebooloptional
127localTemplateboolThis is TRUE If the current template is a Local instance of a Global template. optional
128archiveDisabledbooloptional
129globalTemplateVersioni32globalTemplateVersion come with the current version of the global template. It only will be populated if the template is a local template. optional
130localTemplateOutdatedboollocalTemplateOutdated is TRUE if the source template version is greater than the local template. It only will be populated if the template is a local template. optional
200structDiffdiff.ChangeTypeoptional
201titleDiffdiff.StringDiffoptional
202descripDiffdiff.StringDiffoptional

Struct: TemplateSelectOpts

KeyFieldTypeDescriptionRequirednessDefault value
1includeTeambooldefault
2includeRootHeadersbooldefault
3includeStepsbooldefault
4includeDocumentsbooldefault
5includeLastPublishedboolLoads both lastPublishedAt and lastPublishedVersion default
6includeLastAuthorbooldefault
7includeStatsbooldefault
8includeTagsbooldefault
9includeDraftsbooldefault
10includeLastModifiedbooldefault
11includeAttributesbooldefault
15includeRefMapbooldefault
16includeOriginalAuthorbooldefault
17includeDocumentUrlsbooloptional

Struct: TemplateTextSearch

KeyFieldTypeDescriptionRequirednessDefault value
1querystringdefault

Full text search against title and description

Struct: TemplateWhereOpts

KeyFieldTypeDescriptionRequirednessDefault value
1teamIdstringdefault
2isArchivedbooloptional
3isPublishedbooloptional
4txtTemplateTextSearchoptional
5metadatalist<metadata.MetadataEntry>See MetadataValue for specific metadata filter criteria optional
6authorIdstringoptional
7rootCategoryIdstringoptional
8modifiedSinceTimei64optional
9modifiedBeforeTimei64optional
10templateTypesset<TemplateType>Will default to TemplateType Job optional
11isLatestArchivedbooloptional
12isLatestPublishedbooloptional
13attributeslist<abac.AbacAttribute>allows template filtering by attributes optional
20pageReqcommon.PageReqoptional
30externalOptscommon.ExternalOptsoptional

Options for choosing records

Struct: TemplateOrder

KeyFieldTypeDescriptionRequirednessDefault value
1fieldTemplateOrderBydefault
2ascbooldefaulttrue

Struct: TemplateQueryResult

KeyFieldTypeDescriptionRequirednessDefault value
1templateslist<JobTemplateModular>default
2pageInfocommon.PageInfooptional

Union: TemplateFetchResult

KeyFieldTypeDescriptionRequirednessDefault value
1templateJobTemplateModulardefault
2errcommon.SystemExceptiondefault

Union: TemplateHistoryResult

KeyFieldTypeDescriptionRequirednessDefault value
1templateJobTemplateModulardefault
2errcommon.SystemExceptiondefault

Struct: TemplatePublicVersion

KeyFieldTypeDescriptionRequirednessDefault value
1jobTemplateIdstringdefault
2publicVersioni32default

Struct: TemplateInfo

KeyFieldTypeDescriptionRequirednessDefault value
1templateIdstringdefault
2templateVersioni32default
3addedAfterIdstringshould be the jobBaseStepId of the stepgroup for uniqueness default
4materializedStepsstep.BaseStepdefault

Templates that were added offline addedAfterId should be previous step/step group id This is needed as step position could have changed by modifying job online

Services

Service: JobTemplateService

Function: JobTemplateService.query

TemplateQueryResult query(TemplateSelectOpts selectOpts,
                          TemplateWhereOpts whereOpts,
                          list<TemplateOrder> order)
    throws common.SystemException
Query a list of Job Templates

Function: JobTemplateService.fetch

map<string, TemplateFetchResult> fetch(TemplateSelectOpts selectOpts,
                                     list<string> templateIds)
    throws common.SystemException
Fetch a specific list of JobTemplates. Returns a hashmap of TemplateFetchResults keyed off template ids. One entry for every requested id. Value in hashmap is either an error indicating that the fetch failed or the JobTemplateModular object for that id.

Function: JobTemplateService.getLatestVersions

map<string, i32> getLatestVersions(list<string> templateIds)
    throws common.SystemException
Fetch a map of the given templates ids to their latest version

Function: JobTemplateService.create

JobTemplate create(string teamId,
                   JobTemplateParams params,
                   list<abac.AbacAttribute> attributes)
    throws common.SystemException
Create a new template

Function: JobTemplateService.update

JobTemplate update(string jobTemplateId,
                   JobTemplateParams params)
    throws common.SystemException
Update template title, description

Function: JobTemplateService.archive

JobTemplate archive(string jobTemplateId)
    throws common.SystemException
Mark a job template as archived. Archived templates cannot be edited or used to start jobs. This marks all versions of the job template as archived

Function: JobTemplateService.unarchive

JobTemplate unarchive(string jobTemplateId)
    throws common.SystemException
Mark a job template as unarchived. This marks all versions of the job template as unarchived

Function: JobTemplateService.publish

JobTemplate publish(string jobTemplateId)
    throws common.SystemException
Publish a job template

Function: JobTemplateService.getPublicVersion

JobTemplate getPublicVersion(string jobTemplateId,
                             i32 publicVersion)
    throws common.SystemException
Get a JobTemplate based on public version.

If publicVersion is 0, get the currently published version

Function: JobTemplateService.fetchPublicVersions

map<string, map<i32, TemplateFetchResult>> fetchPublicVersions(TemplateSelectOpts selectOpts,
                                                           list<TemplatePublicVersion> versions)
    throws common.SystemException
Get a list of JobTemplateModulars based on a list of template ids and their public versions.

If publicVersion is 0, get the currently published version.

Returns a map> response.

Function: JobTemplateService.fetchPublishedVersions

map<string, map<i32, TemplateFetchResult>> fetchPublishedVersions(TemplateSelectOpts selectOpts,
                                                              list<TemplatePublicVersion> versions)
    throws common.SystemException
Get a list of JobTemplateModulars based on a list of template ids and their published versions.

If publicVersion (publishedVersion) is 0, get the currently published version.

Returns a map> response.

Function: JobTemplateService.beginReview

i32 beginReview(string jobTemplateId)
    throws common.SystemException
Enter review state, which means that editing will be locked until the review process ends; also generates a new public version number which is returned. When configured, this will also call a registered webhook.

During review state, all operations which add or update content will fail with an error.

Function: JobTemplateService.endReview

i32 endReview(string jobTemplateId)
    throws common.SystemException
Exit review state, release editing lock; returns current public version number.

Function: JobTemplateService.publishVersion

JobTemplate publishVersion(string jobTemplateId,
                           i32 publicVersion)
    throws common.SystemException
Publish a specified version of the job template; must be called AFTER endReview

Function: JobTemplateService.cloneTemplate

JobTemplate cloneTemplate(string jobTemplateId)
    throws common.SystemException
Clone an entire template. ErrorCodes: RESOURCE_ARCHIVED - returned when there exist steps in the copied template that are assigned to an archived role

Function: JobTemplateService.createLocalTemplate

JobTemplate createLocalTemplate(string jobTemplateId)
    throws common.SystemException
Create a new local template from the global template specified by jobTemplateId.

Function: JobTemplateService.addStepModular

JobTemplateModular addStepModular(string jobTemplateId,
                                  string parentId,
                                  step.BaseStep step,
                                  i32 position,
                                  bool replace)
    throws common.SystemException
Add a step to a step group in a job template and return modular template.

Function: JobTemplateService.addStepGroupModular

JobTemplateModular addStepGroupModular(string jobTemplateId,
                                       string parentId,
                                       step.BaseStep stepGroup,
                                       i32 position,
                                       bool replace)
    throws common.SystemException
Add a step group to a step group in a job template and return modular template.

Function: JobTemplateService.moveStepModular

JobTemplateModular moveStepModular(string jobTemplateId,
                                   string parentId,
                                   string stepId,
                                   i32 oldPosition,
                                   string newParentId,
                                   i32 newPosition)
    throws common.SystemException
Move a step to a step group in a job template and return modular template.

Function: JobTemplateService.moveStepGroupModular

JobTemplateModular moveStepGroupModular(string jobTemplateId,
                                        string parentId,
                                        string stepGroupId,
                                        i32 oldPosition,
                                        string newParentId,
                                        i32 newPosition)
    throws common.SystemException
Move a step group to a step group in a job template and return modular template.

Function: JobTemplateService.removeStepModular

JobTemplateModular removeStepModular(string jobTemplateId,
                                     string parentId,
                                     string stepId,
                                     i32 position)
    throws common.SystemException
Remove a step from a step group in a job template and return modular template.

position is the position the step is currently at.

Function: JobTemplateService.removeStepGroupModular

JobTemplateModular removeStepGroupModular(string jobTemplateId,
                                          string parentId,
                                          string stepGroupId,
                                          i32 position)
    throws common.SystemException
Remove a step group from a step group in a job template and return modular template.

position is the position the step group is currently at.

Function: JobTemplateService.cloneStepModular

JobTemplateModular cloneStepModular(string jobTemplateId,
                                    string parentId,
                                    string stepId,
                                    i32 position,
                                    string newParentId,
                                    i32 newPosition)
    throws common.SystemException
Clone a step in a job template and return modular template.

Function: JobTemplateService.cloneStepGroupModular

JobTemplateModular cloneStepGroupModular(string jobTemplateId,
                                         string parentId,
                                         string stepGroupId,
                                         i32 position,
                                         string newParentId,
                                         i32 newPosition)
    throws common.SystemException
Clone a step group in a job template and return modular template.

Function: JobTemplateService.addDocument

JobTemplate addDocument(string jobTemplateId,
                        i32 jobTemplateVersion,
                        string documentId)
    throws common.SystemException
Add a document to a Job Template; update version

Function: JobTemplateService.removeDocument

JobTemplate removeDocument(string jobTemplateId,
                           string documentId)
    throws common.SystemException
Remove a document from a Job Template; update version

Function: JobTemplateService.updateDocument

JobTemplate updateDocument(string jobTemplateId,
                           string documentId,
                           i32 position)
    throws common.SystemException
Update a document to a Job Template; update version

Function: JobTemplateService.updateMetadata

map<string, metadata.MetadataEntry> updateMetadata(string jobTemplateId,
                                                 map<string, metadata.MetadataValue> updated,
                                                 list<string> removedIds)
    throws common.SystemException
Update the metadata on a template. Updated are the values to be added or updated on the template. RemovedIds are the IDs of the values to be removed from the template.

Function: JobTemplateService.acquireLock

JobTemplateLock acquireLock(string jobTemplateId)
    throws common.SystemException, JobTemplateLockFailed
Start editing the template Note that this lock is associated with the specific authToken used, not just the user owning that token. The life of the lock is until releaseLock (which should be called when editing is complete), forcible takeover, or implicitly on logout. Returns the new lock on success. If the lock is already owned by another token, raises JobTemplateLockFailed with previous lock information.

Function: JobTemplateService.forceAcquireLock

ForceAcquireResponse forceAcquireLock(string jobTemplateId)
    throws common.SystemException
Start editing the template, forcibly taking over any existing lock. Note that this lock is associated with the specific authToken used, not just the user owning that token. The life of the lock is until releaseLock (which should be called when editing is complete), forcible takeover, or implicitly on logout. Returns the new lock in the response structure. If the lock was owned by another token, also returns details of previous lock. This method is intended to be called after acquireLock fails and an explicit user response to forcibly take the lock. WARNING: this could result in data loss if another user is editing.

Function: JobTemplateService.releaseLock

void releaseLock(string jobTemplateId)
    throws common.SystemException
Release the lock on the template; will throw exception if you don't have the lock

Function: JobTemplateService.getHistory

map<i32, TemplateHistoryResult> getHistory(string id,
                                         list<i32> internalVersions,
                                         i32 otherVersion)
    throws common.SystemException
Get diff of requested version of a template against the latest version Returns a hashmap keyed off version. One entry for every requested internalVersion. Value is either an error indicating something went wrong with the diffing operation for that version or the JobTemplateModular object with diff fields filled in

Function: JobTemplateService.revert

void revert(string id,
            i32 internalVersion)
    throws common.SystemException
Copies the draft version referred to on top of the current latest draft version

Function: JobTemplateService.updateAttribute

list<abac.AbacAttribute> updateAttribute(common.UUID templateId,
                                         string attributeId,
                                         list<abac.AbacAttributeValue> values,
                                         abac.AbacUploadBehaviour behave)
    throws common.SystemException
Update a single attribute on a job template return value will always be a list with a single attribute determined by which attribute was updated param templateId: job template to update param attributeId: the AttributeId of the team level attribute to be updated param values: the new AttributeValues to associated with Attribute attributeId on template templateId param behave: determine the behaviour of the endpoint, merge or clobber. Default: clobber