My series of Cloud Application Studio Blogs

Suppose the requirement is to display “Assigned Organization Unit ID” of current log on user in your custom UI, for example if I log on system with business user for Jerry, it is expected that my current organization unit ID TESTORG will be displayed in my custom UI.

There are two approaches to achieve this in Cloud Application Studio.

Approach1: Implement AfterLoading event

Create a transient field in custom BO:

Implement the AfterLoading event:

Source code of AfterLoading Implementation:

var uuid = JerryTestReuse.getCurrentEmployeeUUID();
this.AssignedOrgIDTransient = JerryTestReuse.getAssignedOrgID( uuid );

In the implementation, two functions defined in Reuse library JerryTestReuse are used:

Source code for function getAssignedOrgID:

import ABSL;
import AP.Common.GDT;
import AP.PC.IdentityManagement.Global;
import AP.FO.BusinessPartner.Global;

var result : DataType::LANGUAGEINDEPENDENT_ENCRYPTED_EXTENDED_Name;

var queryByEmployeeBPUUID = Employee.QueryByIdentification;
var queryByEmployeeBPUUIDParameter = queryByEmployeeBPUUID.CreateSelectionParams();
queryByEmployeeBPUUIDParameter.Add( queryByEmployeeBPUUID.UUID.content, "I", "EQ", ivUUID.content);
var employeeQueryResult = queryByEmployeeBPUUID.Execute(queryByEmployeeBPUUIDParameter);
var EmployeeQueryResultCurrent = employeeQueryResult.GetFirst();
var assignedOrg = EmployeeQueryResultCurrent.OrganisationalUnitAssignment.GetFirst();
var org = assignedOrg.ToRoot;

result = org.ID;
return result;

Source code for function getCurrentEmployeeUUID:

import ABSL;
import AP.Common.GDT;
import AP.PC.IdentityManagement.Global;
import AP.FO.BusinessPartner.Global;

var result : DataType::UUID;

var queryByIdentityUUID = Identity.QueryByElements;
var queryByIdentityUUIDParameter = queryByIdentityUUID.CreateSelectionParams();
var queryByEmployeeBPUUID = Employee.QueryByIdentification;
var queryByEmployeeBPUUIDParameter = queryByEmployeeBPUUID.CreateSelectionParams();
var id = Context.GetCurrentIdentityUUID().content;
queryByIdentityUUIDParameter.Add( queryByIdentityUUID.UUID.content, "I", "EQ", id.ToString() );
var queryResult = queryByIdentityUUID.Execute(queryByIdentityUUIDParameter);
var first = queryResult.GetFirst(); // points to identity instance
var person = first.Person;
result = person.UUID;
return result;

Approach2: Specify a transformation to a dedicated field

First create another function in Reuse Library:

Source code:

import ABSL;
import AP.Common.GDT;

var result : DataType::LANGUAGEINDEPENDENT_ENCRYPTED_EXTENDED_Name;

var uuid = JerryTestReuse.getCurrentEmployeeUUID();
result = JerryTestReuse.getAssignedOrgID(uuid);
return result;

Create a new data field in UI Model,

And create a new transformation and assigned to this field:

When assigning the transformation to the Data field, you should see this popup dialog,

Choose Yes to convert the Data field into a Dedicated Field. Once done, the assigned transformation will be displayed in Properties window.

When you test both solution in UI, you could observe that the execution of AfterLoading and Transformation and done in the backend and calculation result is contained in HTTP response.

This is different from the behavior introduced in blog How to change UI element visibility dynamically via Rule Editor – and how it works under the hood – in that case the visibility calculation is performed in frontend instead.

Further reading

In CRM there is also similar function supported – so called Calculated Fields created and edited in SAP CRM Application Enhancement Tool ( AET ). Please see more technical detail about Calculated Fields in CRM from this blog
Insight into calculated fields created by AET.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":


注销
1k 声望1.6k 粉丝

invalid