on 12-09-2013 6:20 AM
SQL server has a standard server function that can generate the current time/server time with GETDATE() which is the datetime when the method/function is called. Is there a similar function in ABSL? What I am trying to do is similar to in standard BOs, where each standard BO has a concept of a Created On/Changed On feature that tracks when the BO is created and when it was last changed, as well as who created the BO and changed the BO with Created By/Changed By. I did not see this as an out of box feature with custom BOs so would like to track when/who the BO is changed as when it was created via ABSL.
Hello,
the following function from the ABSL namespace is probably what you are looking for:
var dt = Context.GetCurrentSystemDateTime();
Regards
-- Reinhold
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rei,
Did you finally manage to finish this task on Created On/Changed On and Created By/Changed By?
If yes can you paste the code to use as a template to finish this for custom Objects ?
Regards
Vinod
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes. I did. I spoke with our core developers and they said the changed/created user/datetime stamping on the standard BOs is a core reuse library not exposed to SDK. So the following is a lean version of the basic functionality that can be easily implemented on the root and any node of the customBO
a. Captures the logged in user when the customBO is created vs. updated
b. Captures the current server date and time when the customBO is saved
1. Add the following fields to the root or node to the custom BO depending on where you want datetime/user history tracking
[Label("Changed By")] [Tooltip("Changed By")] element ChangedByID : BusinessPartnerInternalID;
[Label("Created By")] [Tooltip("Created By")] element CreatedByID : BusinessPartnerInternalID;
[Label("Changed On")] [Tooltip("Changed On")] element ChangedOnDate : Date;
[Label("Created On")] [Tooltip("Created On")] element CreatedOnDate : Date;
[Label("Changed On Time")] [Tooltip("Changed On Time")] element ChangedOnTime : Time;
[Label("Created On Time")] [Tooltip("Created On Time")] element CreatedOnTime : Time;
2. Add the following associations to the custom BO
association ChangedBy to Employee;
association CreatedBy to Employee;
3. Add the following to the aftermodify script to the custom BO
importABSL;
importAP.PC.IdentityManagement.Global;
importAP.FO.BusinessPartner.Global;
//get identity/employee Internal ID
varidentity;
varemployee;
identity = Identity.Retrieve(Context.GetCurrentIdentityUUID());
if (identity.IsSet() ){
Trace.Info("I", "Identity found");
employee = BusinessPartner.Retrieve(identity.BusinessPartnerUUID);
if ( employee.IsSet() ){
Trace.Info("I", "Employee found");
}
}
//check and set Created By to logged in user if not set for the first time
if (this.CreatedByID.IsInitial()){
Trace.Info("I", "Created By not set");
this.CreatedByID = employee.InternalID;
}
//set Changed By to logged in user
this.ChangedByID = employee.InternalID;
//query the employee BO to get the createdby related data
varquery_createdby;
varcreatedby_selparam;
varcreatedby_instance;
varquery_createdby_result;
query_createdby = Employee.QueryByIdentification;
createdby_selparam = query_createdby.CreateSelectionParams();
createdby_selparam.Add(query_createdby.InternalID, "I", "EQ", this.CreatedByID);
query_createdby_result = query_createdby.Execute(createdby_selparam);
if (query_createdby_result.Count() == 0) {
this.CreatedBy.Reset();
}
else {
foreach (createdby_instanceinquery_createdby_result) {
this.CreatedBy = createdby_instance;
break;
}
}
//query the employee BO to get the changedby related data
varquery_changedby;
varchangedby_selparam;
varchangedby_instance;
varquery_changedby_result;
query_changedby = Employee.QueryByIdentification;
changedby_selparam = query_changedby.CreateSelectionParams();
changedby_selparam.Add(query_changedby.InternalID, "I", "EQ", this.ChangedByID);
query_changedby_result = query_changedby.Execute(changedby_selparam);
if (query_changedby_result.Count() == 0) {
this.ChangedBy.Reset();
}
else {
foreach (changedby_instanceinquery_changedby_result) {
this.ChangedBy = changedby_instance;
break;
}
}
4. Add the following to the beforesave script to the custom BO
import ABSL;
import AP.FO.BusinessPartner.Global;
import AP.PC.IdentityManagement.Global;
// set the changed on to UTC system time.
var UTCDateTime = Context.GetCurrentGlobalDateTime();
this.ChangedOnDate = UTCDateTime.ConvertToDate();
this.ChangedOnTime = UTCDateTime.GetTime();
if (this.CreatedOnDate.IsInitial()) {
Trace.Info("I", "Created On not set");
this.CreatedOnDate = this.ChangedOnDate;
this.CreatedOnTime = this.ChangedOnTime;
}
5. Activate the customBO
6. Build the UI to display the data on the Thing Inspector, Quick View, and OWL
I used a Compound Field for the date and time fields
Everything should be static text since a user should never edit these fields. The Changed By and Created By should show the "Name" of the user opposed to the ID which the BO stores. In step 2 where you add the associations to the BO, this will allow you to "join" the custom BO with the Business Partner BO so you can display the name stored in the Business Partner BO on the custom BO UI. The path of the user "Name" in the Business partner is the following
Root-> ChangedBy (this is the association you created in step 3) -> Common -> BusinessPartnerFormattedName
Do the same for CreatedBy as well.
*TIP* If you model your associations to the Business Partner in this way, this is the easiest way to display the name and addresses of any business partner on a custom BO without having to store it on the custom BO (you of course need to store the Business Partner ID so you can do the join between the custom BO and the Business Partner BO). The Business Partner BO stores data for Accounts, Contacts, Individual Customers, Partners, Partner Contacts, Employees for Cloud for Customer.
Hi Rei Kasai,
And this would give you the current User's Identity UUID -
UserUUID = Context.GetCurrentIdentityUUID();
In the other post I had mentioned how to get the User as well. But its better to store UUID is my feeling.
But I feel it would be really great if SAP releases out a standard way( probably a How to Guide) for realizing this requirement as this is quite common and I think such common requirements should be done in a standard way.
we were discussing the same requirement a week back in our project as well.
We have not yet realized, in case you did do paste some code to save the time for all.
Regards
Vinod
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
25 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.