Use Calendar Task APIs
You can use calendar task APIs in SAP Analytics Cloud, analytics designer to submit and decline or approve and reject a calendar task. Furthermore you can enquire the properties of a calendar task and you can 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. The APIs are available on a technical object called CalendarIntegration.
Use the CalendarIntegration Technical Object
To create a technical object CalendarIntegration, click in section Calendar Integration in the Outline. A side panel opens where you can set the name of the CalendarIntegration. An additional setting Show Calendar Toolbar at Runtime allows you to control if the specific calendar toolbar should be visible at runtime. The calendar toolbar is shown by default.
-
CalendarIntegration.getCurrentTask()
-
CalendarIntegration.getCurrentTask().getStatus()
-
CalendarIntegration.getCurrentTask().getType()
-
CalendarIntegration.getCurrentTask().hasUserRole(CalendarTaskUserRoleType)
-
general task
-
composite task
-
review task
Use the getCurrentTask API
You can use the getCurrentTask API to inquire the calendar task that is loaded with your analytic application.
var calendarTask = CalendarIntegration_1.getCurrentTask(); console.log(calendarTask);
Use the 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 above returns the task status from the calendar task as noted below:
Use the 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 the 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 the 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 the 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 the 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 the 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 the 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 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 the 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 the getRelatedTaskIds() API
You can use the getRelatedTaskIds() API to retrieve all the calendar task ids for which the opened application 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 the 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 the 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 will change 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 the canUserApprove API
You can use the canUserApprove API for the user role reviewer on a composite sask, 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 the 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 he 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()); }