SAP Cloud for Customer Oberon视图里的Ruby Script Where could Ruby Script be inserted in UI Designer How to debug Script in the runtime

In C4C Oberon views developed by UI Designer it is allowed to write Ruby script at some given position. Once you activate the Oberon view in UI Designer, corresponding JavaScript code will automatically be created and visible in XRepository. Here below are some typical positions where Ruby Script could be inserted:

(1) In Event operation with type “Script”

SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime

Ruby Script:

if ($data.UIState.ViewSwitchSelectedItem == "Collections")
       $controller.HandleEvent("OnRefreshCollection");
end

The corresponding JavaScript code is then visible in view’s source code in XRepository:

SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime

(2) In Operation configure tab:

SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime
SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime

The automatically generated JavaScript code:

SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime

(3) Dynamical manipulation on the value of control attribute via Script
Take “Visible” for example:

SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime

Then you can write script here:

SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime

How to debug Script in the runtime

Set a breakpoint in function _executeScript in file resources/sap/client/evt/ClientOperation.js.
In the runtime, a new JavaScript function will be dynamically created based on the source code stored in XRepository in line 292, and immediately gets called in subsequent line 293.

SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime
SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime

Still take the Script above as example, if you just would like to know the actual value of $System.ClientType in the runtime, it is not necessary to figure it out via debugging.
Instead, append the url fragment “debugMode=true”, and then launch application again.

SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime

Press control key and click page, the client Inspector will be opened. Switch to tab “Data Model”, search by keyword “ClientType”, and then you can get its runtime value “NEW_HTML”.

SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
SAP Cloud for Customer Oberon视图里的Ruby Script
Where could Ruby Script be inserted in UI Designer
How to debug Script in the runtime