两种在SAP Cloud Application Studio里通过编程对C4C UI字段赋值的方法

My series of Cloud Application Studio Blogs

  • How to detect EditMode in an Embedded Component
  • Step by step to enable your custom BO with attachment upload functionality
  • Step by step to create an Adobe Print form in Cloud application Studio
  • How to render PDF which displays picture from the image attachment of your custom BO
  • How to get current logged on business user’s employee information and assigned organization unit via ABSL
  • How to implement dynamic access control based on custom BO using OWL
  • How to make Code List Restriction work when control field and restricted field are not on the same BO
  • How to implement custom number range using custom business object
  • Two approaches to create Code List in Cloud Studio
  • Create Dynamic Code List via Custom Business Object Association
  • Step by step to develop Thing Type based navigation and BO Object based navigation
  • Put Extension field into embedded component and make it visible in Standard UI
  • One possible cause that embedded component fails to display in UI
  • Step by step to create HTML Mashup and make it visible in UI
  • Step by step to enable Text Collection for your custom BO
  • Automatically send an Email notification to line manager via Workflow in Account application
  • Step by step to create Object Value Selector in Cloud Application Studio
  • Two approaches to fill an UI field with dedicated logic implemented in Cloud Application Studio
  • How to execute BO action on multiple selected BO instances in AdvancedListPane
  • How to add custom validation logic on mobile phone field in Contact TI

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的原创文章,请关注公众号"汪子熙":


你可能感兴趣的:(两种在SAP Cloud Application Studio里通过编程对C4C UI字段赋值的方法)