Supply Chain Management Blogs by Members
Learn about SAP SCM software from firsthand experiences of community members. Share your own post and join the conversation about supply chain management.
cancel
Showing results for 
Search instead for 
Did you mean: 
awaes59
Explorer
0 Kudos

Introduction

awaes59_11-1714469409708.png

In today’s data-driven world, integrating different platforms to enhance business intelligence and data analysis capabilities is crucial.

This article provides a guide on integrating SAP Field Service Management (FSM) with PowerBI. Notably, there is no standard connector between these two platforms, necessitating a workaround for effective data utilization. Here, we'll explore how to overcome the authentication challenges using OAuth2 and subsequently fetch data into PowerBI.

 

1. Introduction to the Challenge

Integrating SAP FSM with PowerBI poses a significant challenge primarily due to the authentication process. SAP FSM requires OAuth2 authentication, which involves token generation not natively supported in PowerBI. This guide aims to address and provide a solution to this issue.

There are many connectors available through PowerBI, like SalesForce, IBM, S4, but no connection to FSM.

awaes59_0-1714467266252.png

 

2. Token Retrieval

Step 1: Understanding OAuth2 Authentication

OAuth2 is an authorization framework that enables applications to obtain limited access to user accounts on an HTTP service. In the context of SAP FSM, it requires setting up an OAuth2 client in the SAP FSM system to generate credentials.

Please refer to the following SAP documentation on how to create these.

You are able to set-up the rights and company assigned to the Client ID you are creating.

awaes59_1-1714467523986.png

Once the Client is created, save the clientSecret in a secured place. This will be the only time the key is shown, so make sure you store it.

Step 2: Scripting the Token Retrieval Function

Open a fresh blank PowerBI report. Go to Transform Data, and add a new "Blank Query".
Then navigate to the Advanced Editor 

awaes59_2-1714467648841.png

Paste this code to create the token retrieval function.

 

()=>
let
 // Concatenates the ClientID & Client Secret and converts to base64
 authKey = "Basic " & Binary.ToText(Text.ToBinary("CLIENTID:CLIENTSECRET"),0),
 url = "https://eu.fsm.cloud.sap",
 // Uses the FSM POST OAuth2/token method to obtain a bearer token
 GetJson = Web.Contents(url,
     [RelativePath="/api/oauth2/v2/token",
         Headers = [#"Authorization"=authKey,
                    #"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"],
         Content = Text.ToBinary("grant_type=client_credentials") 
     ]
 ),
 FormatAsJson = Json.Document(GetJson),
 // Gets token from the Json response
 AccessToken = FormatAsJson[access_token],
 AccessTokenHeader = "bearer " & AccessToken
in
    AccessTokenHeader

 

 Don't forget to replace the CLIENTID:CLIENTSECRET part with the values previously created.

Now, when you run this function, it should retrieve a bearer token.
If you encounter this warning : edit credentials, and select "Anonymous"

awaes59_3-1714467955693.png

awaes59_4-1714468002611.png

You should be able now to retrieve the token, and the hardest part is complete. 

awaes59_5-1714468100367.png

Rename this function "GET Token"

awaes59_6-1714468248045.png

 

3. Fetching Data from SAP FSM

Creating the Data Fetch Function

Like before, create a new blank query, and paste this code

 

(query as text, DTOs as text, companyName as text, tenantName as text) =>
let
Source = Json.Document(Web.Contents("https://eu.fsm.cloud.sap", 
[RelativePath="/api/query/v1?dtos=" & DTOs  & "&query="
& query & "&account=" & tenantName  & "&company=" & companyName & "&useExternalIds=true",
    Headers=[Authorization="" & #"GET Token"(), #"Content-Type"="application/json",#"x-client-ID"="cpi", #"x-client-version"="1.0"]])),
    data = Source[data],
    data1 = data
in
    data1

 

This function is calling SAP FSM Query API (documentation here) using the previouslys created function GET Token.
4 parameters are waited : 

  • query: this is the query you want to make on FSM
  • DTOs: this is the list of DTOs for the query
  • companyName: this is the company you want to query on FSM
  • companyTenant: this is the tenant of your FSM account

When saving, this should now look like this:

awaes59_7-1714468491178.png

As you can see, this function can now be called as you wish. This will be the next step: invoke this query and create our first query. You can rename this "FSM Query".

4. Utilizing the Function

Here’s how you can use the above function to fetch and load data into PowerBI :

Enter the 4 parameters, and click on Invoke.

awaes59_8-1714468645954.png

This will create a new query on the left side, with the result from FSM.

awaes59_9-1714468984388.png

And by playing with PowerBI standard functionnality, you'll be able to expand, rename columns, add conditionnal logic; etc.

awaes59_10-1714469082337.png

That's it! You now have all data in your PowerBI, and are able to query as much as you want the system.

 

Disclaimer

It's important to note that embedding credentials directly in your PowerBI files is not secure.
The client ID and client secret are visible in plain text, which poses a security risk.

SAP recommends using SAP Analytics Cloud for business intelligence to ensure better security and integration.

 

Labels in this area