Use Calendar Integration Technical Objects and Calendar Task APIs
As an application designer or story developer, you can add a calendar integration technical object and use calendar task APIs on it, to submit, decline, approve, reject and activate a calendar task, for example. Furthermore, you can enquire the properties of a calendar task and use convenience APIs to verify if you can perform a task status change. The calendar task must be either of type general task, review task or composite task.
Add a Calendar Integration Technical Object
To add a calendar integration technical object, in the Scripting section of the Outline panel, (for analytic applications) choose right next to Calendar Integration, or (for optimized stories) choose .
A side panel opens where you can set the ID of the technical object and choose whether the calendar toolbar is visible in view time.
-
CalendarIntegration.getCurrentTask()
-
CalendarIntegration.getCurrentTask().getStatus()
-
CalendarIntegration.getCurrentTask().getType()
-
CalendarIntegration.getCurrentTask().hasUserRole(CalendarTaskUserRoleType)
-
general task
-
composite task
-
review task
Use getCurrentTask API
You can use the getCurrentTask API to inquire the calendar task that is loaded with your analytic application or story.
var calendarTask = CalendarIntegration_1.getCurrentTask(); console.log(calendarTask);
Use getStatus API
You can get the overall status of a calendar task by using the getStatus API. The API returns a CalendarTaskStatus
var status = CalendarIntegration_1.getCurrentTask().getStatus(); switch (status) { case CalendarTaskStatus.InProgress: console.log("In Progress"); break; case CalendarTaskStatus.Canceled: console.log("Canceled"); break; case CalendarTaskStatus.OnHold: console.log("OnHold"); break; case CalendarTaskStatus.Open: console.log("Open"); break; }
The code snippet returns the task status from the calendar task:
Use getType API
You can get the task type of a calendar task by using the getType API. The API returns the type of task that is created in the calendar (general, composite or review task).
var calendarTaskType = CalendarIntegration_1.getCurrentTask().getType(); console.log(calendarTaskType);
Use hasUserRole API
-
CalendarTaskUserRoleType.Reviewer
-
CalendarTaskUserRoleType.Owner
-
CalendarTaskUserRoleType.Assignee
The API returns true if the current logged in user has the specified user role given as parameter, and false otherwise.
var calendarTask = CalendarIntegration_1.getCurrentTask(); var isReviewer = calendarTask.hasUserRole(CalendarTaskUserRoleType.Reviewer); console.log(isReviewer);
Use submit API
-
CalendarGeneralTask.submit()
-
CalendarCompositeTask.submit()
var calendarTask = CalendarIntegration_1.getCurrentTask(); var isAssignee = calendarTask.hasUserRole(CalendarTaskUserRoleType.Assignee); var calendarTaskStatus = calendarTask.getStatus(); var calendarTaskType = calendarTask.getType(); if (isAssignee && calendarTaskType === CalendarTaskType.CompositeTask && calendarTaskStatus === CalendarTaskStatus.InProgress) { var compositeTask = cast(Type.CalendarCompositeTask, calendarTask); var isSuccessfullySubmitted = compositeTask.submit(); if (isSuccessfullySubmitted) { console.log("You have successfully submitted your task."); } else { console.log("Sorry, something went wrong."); } }
The API replaces the Submit action from the calendar view:
Use decline API
-
CalendarCompositeTask.decline()
-
CalendarGeneralTask.decline()
var calendarTask = CalendarIntegration_1.getCurrentTask(); var isAssignee = calendarTask.hasUserRole(CalendarTaskUserRoleType.Assignee); var calendarTaskType = calendarTask.getType(); if (isAssignee && calendarTaskType === CalendarTaskType.CompositeTask) { var compositeTask = cast(Type.CalendarCompositeTask, calendarTask); var isSuccessfullyDeclined = compositeTask.decline(); if (isSuccessfullyDeclined) { console.log("You have successfully declined your task."); } else { console.log("Sorry, something went wrong."); } }
This API replaces the Decline action from the side panel of the calendar.
Use approve API
-
CalendarCompositeTask.approve()
-
CalendarReviewTask.approve()
var calendarTask = CalendarIntegration_1.getCurrentTask(); var isReviewer = calendarTask.hasUserRole(CalendarTaskUserRoleType.Reviewer); var calendarTaskType = calendarTask.getType(); if (isReviewer && calendarTaskType === CalendarTaskType.ReviewTask) { var reviewTask = cast(Type.CalendarReviewTask, calendarTask); var isSuccessfullyApproved = reviewTask.approve(); if (isSuccessfullyApproved) { console.log("You have successfully approved the task of the assignee."); } else { console.log("Sorry, something went wrong."); } }
The API replaces the Approve action from the side panel of the calendar.
Use reject API
-
CalendarCompositeTask.reject()
-
CalendarReviewTask.reject()
var calendarTask = CalendarIntegration_1.getCurrentTask(); var compositeTask = cast(Type.CalendarCompositeTask, calendarTask); var isSuccessfullyRejected = compositeTask.reject(); if (isSuccessfullyRejected) { console.log("You have successfully rejected your task."); } else { console.log("Sorry, something went wrong."); }
The API replaces the Reject action from the calendar toolbar or from the side panel of the calendar.
Use getCalendarTaskById() API
If you want to retrieve information about a specific task, you can use the getCalendarTaskById() API. Simply pass the eventId from the query string in the URL The analytic application or story doesn't need to be opened by clicking a work file from the calendar task to use this API.
var task = CalendarIntegration_1.getCalendarTaskById("taskId"); if (task.getType() === CalendarTaskType.CompositeTask) { console.log("This is a composite task"); } else if (task.getType() === CalendarTaskType.GeneralTask) { console.log("This is a general task"); } else if (task.getType() === CalendarTaskType.ReviewTask) { console.log("This is a review task"); }
Use activate() API
You can use the activate() API to activate a task and also specify the notify option. This API replaces the Activate or Activate and Notify option from the calendar view.
Use getRelatedTaskIds() API
You can use the getRelatedTaskIds() API to retrieve all the calendar task ids for which the opened application or story is a working file. The API returns either an array of task ids, or if no tasks are found, an empty array.
Recurring composite tasks are currently not delivered as part of the result.
var allTasks = CalendarIntegration_1.getRelatedTaskIds(); console.log(allTasks);
Use createCompositeTask() API
You can use the createCompositeTask() API to create a composite task with properties and options.
When creating a composite task, you can choose a name, startDate and dueDate, which are the mandatory properties. You can choose between an analytic application or a story when specifying the work file.
var newTask = CalendarIntegration_1.createCompositeTask({ name: "newCompositeTask", startDate:new Date(Date.now()), dueDate: new Date(2022, 0, 16, 0, 0, 0), workFiles: [{ id: Application.getInfo().id, type: CalendarTaskWorkFileType.AnalyticApplication, }], assignees: [Application.getUserInfo().id], description: "Calendar Composite Task description", reviewers: { "1": ["reviewerId"], } }, { autoActivate: true });
Use the Status Change APIs for a Calendar Composite Task
You can use the submit(), decline(), approve() or reject() APIs for any composite task given a task Id.
var task = CalendarIntegration_1.getCalendarTaskById("taskId"); if (task.getType() === CalendarTaskType.CompositeTask) { var compositeTask = cast (Type.CalendarCompositeTask, task); compositeTask.submit(); }
Use Calendar Task Convenience APIs
You can use the technical object CalendarIntegration together with the convenience APIs canUserSumit,, canUserDecline, canUserApprove, canUserReject to check if you can perform a task status change.
-
general task
-
composite task
-
review task
To use these APIs, you first have to convert a technical object CalendarIntegration to the target event using the cast() API.
Use canUserSubmit API
You can use the canUserSubmit API to verify if a calendar task is ready to be submitted for the assignee user role. If you use the API when the task status is Open , the task status changes to In Progress.
var task = CalendarIntegration_1.getCalendarTaskById("myTaskId"); var compositeTask = cast (Type.CalendarCompositeTask, task); var canSubmit = compositeTask.canUserSubmit(); if (canSubmit) { var submitSuccesfull = compositeTask.submit(); if (submitSuccesfull) { console.log("Submitted"); } else { console.log("Failed to submit, please try again."); } }
Use canUserApprove API
You can use the canUserApprove API for the user role reviewer on a composite task, or for a user role assignee on a review task to verify if the task can be approved.
var allTasks = CalendarIntegration_1.getRelatedTaskIds(); for (var i=0; i<allTasks.length;i++) { var task = CalendarIntegration_1.getCalendarTaskById(allTasks[i]); if (task.getType() === CalendarTaskType.CompositeTask) { var compositeTask = cast (Type.CalendarCompositeTask, task); var canApprove = compositeTask.canUserApprove(); if (canApprove) { console.log("Approving task with details" + task.getName() + "and with id" + task.getId()); console.log(compositeTask.approve()); } else { console.log("Cannot approve task with details" + task.getName() + "and with id" + task.getId()); } } else if (task.getType() === CalendarTaskType.ReviewTask){ var reviewTask = cast (Type.CalendarReviewTask, task); var canApproveReviewTask= reviewTask.canUserApprove(); if (canApproveReviewTask) { console.log("Approving task with details" + task.getName() + "and with id" + task.getId()); console.log(reviewTask.approve()); } else { console.log("Cannot approve task with details" + task.getName() + "and with id" + task.getId()); } } }
Use canUserReject API
You can use the canUserReject API for the user role reviewer on a composite task or for the userrRole assignee on a review task, to check if the task can be rejected.
var allTasks = CalendarIntegration_1.getRelatedTaskIds(); for (var i=0; i<allTasks.length;i++) { var task = CalendarIntegration_1.getCalendarTaskById(allTasks[i]); if (task.getType() === CalendarTaskType.CompositeTask) { var compositeTask = cast (Type.CalendarCompositeTask, task); var canReject = compositeTask.canUserReject(); if (canReject) { console.log("Rejecting task with details" + task.getName() + "and with id" + task.getId()); console.log(compositeTask.reject()); } else { console.log("Cannot reject task with details" + task.getName() + "and with id" + task.getId()); } } }
Use canUserDecline API
You can use the canUserDecline API for the user role assignee on a composite or a general task to verify if the task can be declined.
var task = CalendarIntegration_1.getCurrentTask(); if (task.getType() === CalendarTaskType.CompositeTask) { var compositeTask= cast (Type.CalendarCompositeTask, task); console.log(compositeTask.canUserDecline()); } else if (task.getType() === CalendarTaskType.GeneralTask){ var generalTask = cast (Type.CalendarGeneralTask, task); console.log(generalTask.canUserDecline()); }