cancel
Showing results for 
Search instead for 
Did you mean: 

How to use SAP Passport at UI Level in CAP Model

former_member686997
Discoverer
0 Kudos
642

How to use SAP Passport for CAP model at UI level so that it is added to header of all service call.

I was following this document =SAP Passport

gregorw
Active Contributor
0 Kudos

Your Link is pointing to an SAP internal resource. This is a public forum. Please check if you can provide an external link.

View Entire Topic
former_member686997
Discoverer
0 Kudos

1, In src/index.js

const libepp = require('@sap/sapdsrpassport');
const Tools = require ('@sap/sapdsrpassport/dist/util/Tools')
const CompTypes = require ('@sap/sapdsrpassport/dist/model/ComponentTypes')
const TFlags = require ('@sap/sapdsrpassport/dist/model/TraceFlags')
let epp = new libepp.DsrPassport();

// Step 1: Create a basic DsrPassport
epp.createV3Passport(
    TFlags.TraceFlags.LOW,                  // (NONE|LOW|MEDIUM|HIGH) Use LOW for just correlation
    "DemoComponent_1",                      // Passport Creator ComponentName
    0,                                      // Service: 0 for "undefined"
    "<dummy>",                              // 
    "action",                               //
    11,                                     // ActionType: 11 denotes HTTP Request
    "DemoComponent_1",                      // Previous Component PreviousComponentName
    Tools.Tools.createGUID(16),    // TransactionID 
    "   ",                                  // In case of ABAP system Source Client, else "   "
    CompTypes.ComponentTypes.TRACELIB,      // Corresponding Component Type (see ComponentTypes)
    Tools.Tools.createGUID(16),    // RootContextId
    Tools.Tools.createGUID(16),    // ConnectionId  
    1);                                     // ConnectionCounter

// Step 2
let strEpp = epp.getPassportAsString();     // get Header Value for SAP-PASSPORT header
console.info(strEpp);

// Step 1: Create a Copy of an existing Passport as Outbound Passport
let eppCopy = new libepp.DsrPassport();     // new DsrPassport Object
eppCopy.parsePassport(strEpp);              // parse header value strEpp into DsrPassport Object

// Step 2: Update relevant fields of the Outbound Passport
eppCopy.setConnectionId(Tools.Tools.createGUID(16));
eppCopy.setConnectionCount(1);
eppCopy.setPreviousComponent("DemoComponent_2");


let strHeader = "SAP-PASSPORT: " + eppCopy.getPassportAsString(); 
console.info(strHeader);

// Access a single SAP Passport field (e.g. TransactionId)

// Example for TransactionId
let transId = epp.getTransactionId();
console.info(transId);

// Example for ConnectionId
let connId = epp.getConnectionId()
console.info(connId);

// Example for ConnectionCounter
let connCt = epp.getConnectionCount()
console.info(connCt);

// Example for ComponentId (=== SystemId)
let compName = epp.getComponentId()
console.info(compName);

let version = epp.getVersion()
console.info(version);

let action = epp.getAction()
console.info(action)

console.info(epp.getPreviousComponentId())




gregorw
Active Contributor
0 Kudos

This is a public website. You're posing here NPM Libraries that are not public. Please reach out to your SAP internal colleagues to answer your questions.