Skip to Content
Technical Articles
Author's profile photo Antonio Maradiaga

How to update a custom view template in the SAP Ariba Analytical Reporting API?

In this blog post I share how to update the fields and filter of a custom view template in the SAP Ariba Analytical Reporting API.

In the documentation of the SAP Ariba Analytical Reporting API, an example of how to update the status of a custom view template is given. There is no example of how the select and filter fields can also be updated by using the patch method (https://openapi.ariba.com/api/analytics-reporting-view/v1/prod/viewTemplates/{MyCustomViewTemplate}/patch) available in the API.

When do you need to update a custom view template?

This will be especially useful when you are developing a reporting application and are unsure of which fields to extract or which filters are required.

It is not possible to modify the system views available (view templates ending in “SystemView”). If you want to “modify” one, just extract the metadata of the system view and use this to create a custom view template.

Creating a view template -> ScorecardFactCustom

Let’s first create a custom view template. In the example below I will use the ScorecardFact document type, with no filters and only a subset of fields.

 

curl --location --request POST 'https://openapi.ariba.com/api/analytics-reporting-view/v1/prod/viewTemplates/ScorecardFactCustom?realm=myrealm-T' \
--header 'Content-Type: application/json' \
--header 'apikey: [MY_API_KEY]' \
--header 'Authorization: Bearer eb04b750-1234-5678-9012-0dca7bdaba2a' \
--data-raw '{
    "documentType": "ScorecardFact",
    "status": "published",
    "selectAttributes": [
        "LoadCreateTime",
        "LoadUpdateTime",
        "Scorecard",
        "SourceSystem",
        "Status",
        "PeriodFrom",
        "PeriodTo",
        "Project",
        "Supplier",
        "Owner",
        "Value",
        "Weight",
        "Target",
        "Grade",
        "SystemGrade",
        "TimeCreated",
        "TimeUpdated"
    ],
    "filterExpressions": []
}'

Updating a view template

Now let’s update the previously created custom view template by adding more fields and specifying some filters.

 

curl --location --request POST 'https://openapi.ariba.com/api/analytics-reporting-view/v1/prod/viewTemplates/ScorecardFactCustom/patch?realm=myrealm-T' \
--header 'Content-Type: application/json' \
--header 'apikey: [MY_API_KEY]' \
--header 'Authorization: Bearer eb04b750-1234-5678-9012-0dca7bdaba2a' \
--data-raw '{
    "status": "published",
    "selectAttributes": [
        "LoadCreateTime",
        "LoadUpdateTime",
        "Scorecard",
        "SourceSystem",
        "Status",
        "PeriodFrom",
        "PeriodTo",
        "Project",
        "Supplier",
        "Owner",
        "Commodity.Commodity",
        "Department.Department",
        "GradeCount",
        "Value",
        "Weight",
        "Target",
        "Grade",
        "SystemGrade",
        "RespondentUser",
        "RespondentDepartment",
        "RespGradeCount",
        "RespondentGrade",
        "TimeCreated",
        "TimeUpdated"
    ],
    "filterExpressions": [
        {
            "name": "WeightValue",
            "field": "Weight",
            "op": "=",
            "defaultValue": 100.0
        },
        {
            "name": "updatedDateTo",
            "field": "TimeUpdated",
            "op": "<=",
            "defaultValue": null
        },
        {
            "name": "updatedDateFrom",
            "field": "TimeUpdated",
            "op": ">",
            "defaultValue": null
        }
    ]
}'

If you now retrieve the metadata of the custom view template (command below), you will see the newly added fields and filters.

curl --location --request GET 'https://openapi.ariba.com/api/analytics-reporting-view/v1/prod/viewTemplates/ScorecardFactCustom?realm=myrealm-T' \
--header 'apikey: [MY_API_KEY]' \
--header 'Authorization: Bearer eb04b750-1234-5678-9012-0dca7bdaba2a'

I hope this little tip helps you when defining your custom view templates and speeds up your development process.

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sreeni v
      Sreeni v

      Hi  Antonio,

      Can you please elaborate little bit more please.   how do I create custom template i need to add 2 custom fields in Requistion template.  Can you help me on this.

      Author's profile photo Antonio Maradiaga
      Antonio Maradiaga
      Blog Post Author

      Hi Sreeni v,

      You first need to see the custom fields available for the document type that you are interested in, via the /metadata endpoint and using the includeCustomFields query parameter. Then, you will need to create a custom view template and there include those custom fields.

      Hope this helps.

      .A