Community perspective: Version switchover management from UX Page with API

Options
Lehtohen
edited December 2023 in Blog

The Anaplan API offers many improvements to model management, which can help improve the data quality and make work more efficient by eliminating repetitive tasks, which are error prone. 

One area where I have found myself doing repetitive tasks is switchover management. Especially when dealing with multiple models it becomes very time consuming to go through each model once a month and to update the switchover value. Also, as updating the switchover is something that can only be done on the model side, the responsibility is not as easily delegated. For example, if the switchover should be updated after a certain event, such as a month closing, it might require input from Controllers who then need to inform a model builder when the update can be performed. 

Luckily with the help of the Anaplan API it is possible to automate the process and allow the management of the switchover from a UX Page. 

In this article I will show how I am able to manage the switchover from a UX Page. Python code examples are included. 

Starting situation:

Switchover for version ‘Switchover_Management_Demo’ is set to ‘Nov 22’. 

Sieppaa.PNG

Step 1: Publish a module to a UX Page

Sieppaa.PNG

We will use the API to read data from the view and iterate through each row and compare the current date to the ‘Closing_Date’ value. If the current date equals ‘Closing_Date’ then the switchover value will be updated accordingly. 

Step 2: Import required libraries and provide required parameters

Required libraries: 

  • Requests
  • Json
  • Pandas
  • Datetime

Required parameters:

  • Workspace Id
  • Model Id
  • Module Id
  • View Id
  • Version Id

Sieppaa.PNG

Step 3: Authenticate and get data from view

Next we need to authenticate ourselves using either basic authentication or certificate based authentication, which will return an authentication token. 

Once we have an authentication token we can proceed to reading data from a view. I suggest checking out the API documentation for reading view data. Similar to file export from a module we need to define the export type, which should be “GRID_ALL_PAGES”. 

The output of the post request will be the requestId, which is needed when downloading the data from the view. 

The downloaded data from the view will be in text format and so Pandas library can be used to modify the data to a more readable format. The code example will create a DataFrame that is easy to iterate through in the next step. 

Sieppaa4.PNG

Step 4: Iterate through rows and compare to today

Next we need to get the date for today and transform it to ‘YYYY-MM-DD’ format. 

Once we have the today value, we can iterate over each row in the DataFrame and check if there is a matching date. If a matching date is found, then the switchover will be updated accordingly and the for loop will break. 

It is good to note that the input for the switchover will be a date instead of a period. In my case the today value would be ‘2022-12-11’, which would set the switchover to ‘Dec 22’.

Sieppaa2.PNG

Step 5: Further development

Changing the switchover can have a major impact on the model, so I suggest adding a few extra steps that would notify users a day or a week before the switchover will be updated. Also once the switchover has been updated a notification email could be sent to selected users. 

End situation:

Sieppaa5.PNG

 

Most of the time the switchover will be updated immediately, but I have noticed that sometimes it takes up to a minute to show up even though the API gives a successful response. If I look at the model history I can see that the switchover has been updated, but it still takes a while to be visible in the grid. 

 

I see great opportunities with the Anaplan API, and I have many API tricks in my sleeve. Feel free to leave a comment or message me on LinkedIn if you are interested to hear more. 

Comments