Technology Blog Posts by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
spurwar
Product and Topic Expert
Product and Topic Expert
0 Likes
619

The Calendar in SAP Analytics Cloud (SAC) is a powerful framework for orchestrating planning processes, tasks, and workflows across teams. Each calendar event or process carries context filters — such as Date, Version, or Proficenter etc. — that define the specific slice of data being worked on by a team or user.

In some cases, administrators or power users may need to update these context filters in bulk, for example when moving from one fiscal year to another.

While this can be done manually using the Calendar List workspace (where multiple events can be selected and edited together), alternatively scripting provides a faster, automated way to achieve the same — especially when you need to apply changes dynamically.

This approach is inspired by the SAP Community blog written by @mike688 
Experience Sharing – How to Batch Modify the Assignees of Calendar Events Using Scripting in SAC, which demonstrates how to modify event assignees in bulk using the Calendar Integration API.

In this post, we extend the same idea — but instead of assignees, we modify dimension context filters for multiple events at once.

Option 1 – Editing Multiple Events via the SAC UI

You can update context filters directly using the Calendar List workspace:

Steps:

  1. Navigate to Calendar → List workspace.

  2. Select multiple events that you want to modify.

  3. Click Edit Events.

spurwar_0-1762844554198.png

  1. Choose Context, and update filters such as Date, Version, or Category.

spurwar_1-1762844603818.png

This method works well for manual batch updates, especially when the changes are straightforward and performed occasionally.For detailed reference, see SAP’s documentation: Editing Multiple Calendar Events at Once

Option 2 – Automating Context Filter Updates Using Scripting

The Calendar Integration API in SAC allows developers to access and modify multiple calendar tasks and processes programmatically.

You can learn more about this API and its supported operations in the official documentation: SAP Help – Calendar Event API Reference

Below is an example that demonstrates how to batch modify Date context filters for all child events of a process. You can also modify the same script to change other dimension context filters also.

Example Scenario

Suppose your planning calendar has multiple child tasks for FY2022.
You now want to update all these tasks to FY2025 automatically.

spurwar_4-1762845999456.png

Step 1:  Accessing the EventID of a Process

To view the event ID of an event, go to the Event Settings dialog and choose Show Details

spurwar_3-1762845732408.png

Step 2: Create a story and add the below code to the story widget.

Prerequisite: Add a Calendar Integration Technical Object

Then, paste the following script:

 

// Step 1: Get main process event
//Replace XXXXXXX with Process Event ID.
var root = CalendarIntegration_1.getCalendarEventById("XXXXXXXXXXXXX");

if (root === undefined) {
    Application.showMessage(ApplicationMessageType.Warning, "Invalid event ID.");
    Application.hideBusyIndicator();
    return;
}

// Step 2: Check event type
if (root.getType() !== CalendarTaskType.Process) {
    Application.showMessage(ApplicationMessageType.Warning, "Only Process type events can be modified.");
    Application.hideBusyIndicator();
    return;
}

// Step 3: Get children
var process = cast(Type.CalendarProcess, root);
var childIds = process.getChildren();

console.log("Child event IDs:");
console.log(childIds);

var targetYear = "2025"; // Enter Target new year for the child event 

// Step 4: Loop through each childs
for (var i = 0; i < childIds.length; i++) {
    var childId = childIds[i];
    console.log("Processing child ID"+childId);

    var ev = CalendarIntegration_1.getCalendarEventById(childId);
    if (ev === undefined) {
        console.log("Skipping invalid child->"+childId);
		       continue;
    }

    // Step 5: Get context filters
    var ctx = ev.getContextFilters();
    console.log("Context filters for child:");
    console.log(ctx);

    // We can’t assign null → use flag and index instead
    var hasDateFilter = false;
    var dateFilterIndex = -1;

    for (var j = 0; j < ctx.length; j++) {
        var f = ctx[j];
        if (f.members && f.members.length > 0 && f.members[0].dimensionId === "Date") {
            hasDateFilter = true;
            dateFilterIndex = j;
            break;
        }
    }

    if (hasDateFilter === false) {
        console.log("No Date filter found for"+childId);
        continue;
    }

    var dateFilter = ctx[dateFilterIndex];
console.log("datefilter");
	console.log(dateFilter);
    // Step 6: Remove old Date filter for the child event
    var removed = ev.removeContextFilter(dateFilter);
    if (removed === true) {

		console.log("Removed old Date filter for -> " + childId);

    } else {
        //console.log("Could not remove Date filter for:", childId);
        continue;
    }

    // Step 7: Build new Date filter dynamically
    var modelId = dateFilter.members[0].modelId;
    var hierarchy = dateFilter.hierarchy;

	var newDateFilter = ArrayUtils.create(Type.CalendarContextFilter); 
			

	newDateFilter = [{
    hierarchy: {
        id: "FYQP",
        description: "FYQP"
    },
    members: [
        {
            dimensionId: "Date",
            id: "[Date].[FYQP].[Date.FISCAL_YEAR].[" + targetYear + "]",
            description: targetYear,
            displayId: targetYear,
            modelId: modelId
        }
    ]
}];

    // Step 8: Add the new Date filter
  ev.addContextFilter(newDateFilter[0]);
  console.log("Added new Date filter (" + targetYear + ") for" + childId);
}

// Step 9: Done
Application.showMessage(ApplicationMessageType.Success, "Date context filters updated successfully for all child events!");
Application.hideBusyIndicator();

 

API Methods Used

MethodPurpose
getCalendarEventById()Fetches a specific event using its ID
getChildren()Retrieves all child events under a process
getContextFilters()Returns all context filters for the event
removeContextFilter()Removes an existing context filter
addContextFilter()Adds a new context filter dynamically

Summary

The Calendarevent API in SAP Analytics Cloud provides a rich set of methods that go well beyond modifying context filters.
You can reuse the same structure to perform a variety of automation and maintenance actions across the planning calendar events.

By combining UI-based editing and scripting automation, SAC administrators can achieve both flexibility and efficiency in managing planning calendars.

3 Comments