Skip to Content
Author's profile photo Sankaran A

Change History (Reuse Library)

In the previous article, we learned, how to embed a change log in the custom business object. Change HistoryHere we are going to learn, how to capture the same in the ABSL scripting.

Change History is a SAP reuse library, which contains a function that you can use to retrieve data from a supplied Business Object and its nodes that were changed during the given period based on the Platform Change Document service.

Prerequisites

Should have a knowledge on Change History (Business Object).

Change History

For more information about the change history Business Object creation, see http://blog.sankaranss.com/2017/06/22/change-history/.


Description

Syntax: <BusinessObject>.Read(“NameSpace”, UUID, NodeID, FromDate, ToDate, User );

  1. BusinessObjectName defines the name of the Business Object.
  2. Define the namespace, e.g,. AP.CRM.Global:Lead.
  3. UUID: Retrieve current instant UUID. To get current UUID, Context.GetCurrentIdentityUUID()
  4. NodeID provides the NodeID of the Root node for the requested instance.
  5. The other four parameters are optional:
    • NodeName: Restricts the result to given node
    • ToChangeDateTime: If no value is given the current date and time is taken
    • FromChangeDateTime: If no value is given 30 days earlier than the ToChangeDateTime is used
    • ChangerUUID: Only the changes made to the respective user are returned.

Example for SAP Business Object
// get all changes of SAP Business Object Lead based upon Lead Root node ID

var myLeadRootNodeId : UUID;
myLeadRootNodeId = …
var currentUser = Context.GetCurrentIdentityUUID();
var myChanges = ChangeHistory.Read( “AP.CRM.Global:Lead”, myLeadRootNodeId, “Root”, this.FromDateTime, this.ToDateTime, currentUser );

 


Example for Custom Business Object
// get all changes of Custom Business Object MyOwnBusinessObject based upon own BO Root node ID

var currentUser = Context.GetCurrentIdentityUUID();
var myChanges = ChangeHistory.Read(“MyOwnBusinessObject”,  this.GetObjectNodeReference().UUID, “Root”);

Testing

Debug the code and check the output as shown in the below screenshot.

Change History

If you like to add some points to this article, kindly leave your points as comments. Don’t forget to subscribe http://blog.sankaranss.com

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Christian Forrester
      Christian Forrester

      Dear Sankaran,

      many thanks for your article. Currently I am calculating some timestamps in PDI (Event-After Modify) to analyse service tickets. Is it possible to use this library to query the time at which the original Assignee was initially set? Do you have an idea how to do this?

      Many thanks for your help.

      Best Regards,

      Christian

      Author's profile photo Doug Hammer
      Doug Hammer

      This is a very interesting Re-Use Library. Thank you for putting this together!

      Regards,
      Doug

      Author's profile photo Frank Scherie
      Frank Scherie

      Dear Sankaran,

      thanks for the interesting post.

      Trying to implement and test with ByDesign I created an Business Object Extension for Customer

       

      import AP.Common.GDT;
      import AP.FO.BusinessPartner.Global;
      import AP.PlatinumEngineering as Platinum;
      
      [Extension] businessobject AP.FO.BusinessPartner.Global:Customer {
       
              // You must activate this business object before you can access the extension fields
              // or messages in script files, forms, and screens.
          
      	node AddressInformation { } 
          	node BankDetails { } 
      	node Common {
      		      element BroadcastUUID :	UUID;
      		} 
          	node CurrentEmployeeResponsible { }  
      }

       

      and added Script for Event-BeforeSave on Root Node according to your  Example for SAP Business Object

       

      import ABSL;
      import AP.PlatinumEngineering as Platinum;
      import AP.Common.GDT;
      import DocumentServices.Global;
      import BASIS.Global;
      
      var debug = 1;
      
      foreach (var root in this)
      {
      
      		var BOName = "AP.FO.BusinessPartner.Global:Customer";
      		var NodeID : UUID;
      		NodeID = root.UUID;
      		var NodeName = "Root";
      		var FromDateTime : GLOBAL_DateTime; //2016-04-19T15:30:00Z
      		var ToDateTime : GLOBAL_DateTime; //2017-04-19T15:30:00Z
      		var ChangedByUUID = Context.GetCurrentIdentityUUID();
      
      		var OppChange = ChangeHistory.Read(BOName, NodeID, NodeName, FromDateTime, ToDateTime, ChangedByUUID);
      
      var debug = 99;
      
      }

      Setting debug breakpoint

      var debug = 99;

      and modifying Customer Data and save, I receive error message:

      "Business object 'Customer' not registered for Change History"


      Changes could be succesfully saved and visible in change log history

      This Works even for extension fields added in adaption mode to Header data (I named it Z_CHANGEHISTORY) but not for extensions to the BO like

      	node Common {
      		      element BroadcastUUID :	UUID;
      		} 

      which is expected (Documentation states that elements are excluded)

      Anyway - I found KB article

      2625662 - Custom Change History Does Not Work

      and applied the following steps

      1.) Creating a BAC Element in Cloud Application Studio including scoping question and activate / save it

      2.) Activated all Objects in in Cloud Application Studio

      3.) Checked in all Objects in in Cloud Application Studio

      4.) Edited Business configuration in ByDesign and checked scoping question (see 1.)

      5.) In in Cloud Application Studio open context menu for for solution in Project Explorer and choosed Deploy Business Configuration

      6.) Choose All content of your solution and Press [OK]

      Result: Deployment to Busines configuration finished succesfull

      7.) Reconnect to ByDesign

      8.) Make changes to Customer and save it - giving still

      "Business object 'Customer' not registered for Change History"

       

      Since documentation states

      "The data of SAP Business Objects are also retrieved in those business objects the Platform Change Document service enabled by SAP"

      I assume Customer of namespace AP.FO.BusinessPartner.Global i.e.AP.FO.BusinessPartner.Global:Customer is not included in the Platform Change Document service whatever this is.

      Going through Business configuration including Questions, Scopings, Finetuning the are no entries matching key word Platform

      Does anyone face the same problem / error or can provide a solution to solve it ?

      Kind regards,
      Frank Scherie