Planning Analytics with Watson

 View Only

Extending PAjs - Chores

By Edward Stuart posted Mon December 19, 2022 08:25 AM

  
In a recent update we found that a number of REST API end points contained a "Name" in the response. 

In the below example I am querying the Chores endpoint, I do this by using:

- Transfer Protocol (SSL = https/ No SSL = http)
- Servername (Localhost)
- HTTPPortNumber (52670)
- APIStub (/api/v1)
- Chores endpoint (Chores)

http://localhost:52670/api/v1/Chores

What I can do here is input this direct to a web browser and it will request credentials:


Upon authenticating then we will see the following output:

Alternatively, through PAjs, we select the Chores menu:


When we inspect the page we can see a console log which displays the full output:


This confirms the two Chores that are present:


The selectItem function has been updated to direct us to a new Chore.html page when a Chore is selected:

function selectObject(item) {
    console.log(item);
    localStorage.setItem("activeObject", item);
    if (activeItem === 'Processes') {
        window.location = '../pages/process.html';
    } else if (activeItem === 'Chores') {
        window.location = '../pages/chore.html';
    } else {
        window.location = '../pages/object.html';
    }

}

From the output we can pull the details from the chore; Start Time, ExecutionMode, Active, DSTSensitive and Frequency:


We could look to expand the Frequency/ Start Time outputs to more human readable format.

When we review the Chore details in the REST API documentation (https://www.ibm.com/docs/en/planning-analytics/2.0.0?topic=data-chores)

The examples provided list:
  • Retrieve a definition of an existing Chore (subjected to security context)
  • Retrieve the chore's basic properties
  • Retrieve the chore's tasks (by using a ChoreTask)
  • Retrieve the chore's execution mode
  • Retrieve a set of chores (subjected to security context)
  • Filter a set of chores (subjected to security context)
  • Retrieve a set of chore properties (subjected to security context)
  • Create a chore (subjected to security context)
  • Modify an existing chore (subjected to security context)
  • Modify a chore's basic properties
  • Add a chore task
  • Remove a chore task
For now we are primarily focused on GET requests, so we will first off GET the processes that reside within the Chore

The IBM example uses the following URL:

http://tm1server:8000/api/v1/Chores('myChore')/Tasks?$expand=Process($select=Name)

At present in PAjs we have the following items available:

So our new GET request will pull the "activeTM1Server", "activeItem" and "activeObject" to generate a request to GET all Processes that reside in the chosen Chore.

const serverUrl = activeTM1Server + activeItem + '(\'' + activeObject + '\')' + '/Tasks?$expand=Process($select=Name)';

Console logging the output confirms that we have a single Process within this Chore but also that the response is an Array:


What we want to do is to list out the Processes that form the Chore:

    for (let i = 0; i < data.value.length; i++) {
        // List Process Names from within the defined Chore
        const processName = document.createElement("h3");
        processName.innerHTML = data.value[i].Process.Name;
        setArticleContainer.appendChild(processName);
    }

We use a FOR loop to check each item in the Array by counting each item until we hit the Array Length. For each Process we encounter we add a new H3 element and populate with the Process Name value:


Excluding some CSS (much needed across the application!) we have the basics of a Chore request available to us and we can see which Processes are comprised within the Chore.

Initially, this would lead to a specific Chores page which will list Chores available per selected AdminHost(s) to confirm which Chores are Active/ In-active and confirm the Daylight Saving Times parameter.

We can replicate the Processes code for CRUD (Create, Read, Update, Delete) operations on Chores.

As I am using the application more and more, I am finding it more useful to traverse to specific pages to get quick access to objects rather than walk through the Planning Analytics link and navigate to each sub-section. 

Over the holiday season updates will be made to the front page to enable users to navigate direct to these mini applications as the purpose of the application is to reduce button clicks

#PlanningAnalyticswithWatson
0 comments
7 views

Permalink