DS API Tips
Enum Constants
Many of the functions in the 3DEXPERIENCE™ REST API accepts a Java Enum constants as arguments, for example when defining what kind of data to be returned etc.
When using this API from the JavaScript Executor, you typically would need to get a reference to the Java Enum type like shown below before using it:
const EngItemMask=Java.type('com.technia.dsx.threedspace.eng.item.EngItemMask');
const EngItemField=Java.type('com.technia.dsx.threedspace.eng.item.EngItemField');
//...
const item = spaceService.getEngItemService().read(session,
itemId,
EngItemMask.DETAILS,
EngItemField.SUPPORTED_TYPES,
EngItemField.CUSTOMER_ATTRIBUTES);
We have recently added experimental support for referencing the Enum Constant by name using a String.
This would then eliminate the need to load/reference the Enum classes via the Java.type
call and only reference the Constant by 'name'.
See below for an example:
const item = spaceService.getEngItemService().read(session,
itemId,
'DETAILS',
'SUPPORTED_TYPES',
'CUSTOMER_ATTRIBUTES');
Code Inclusion
In order to allow reusing code among different configurations, you can include another configuration via this syntax:
//@include:NAME_OF_CONFIG_TO_BE_INCLUDED
An example of using this could be to declare references to Java API classes in one place, then just include that to avoid having to add these in all configurations.
Example: DSXAPI.js
const ExportInput=Java.type('com.technia.dsx.exchange.export.ExportInput');
const ExportParameters=Java.type('com.technia.dsx.exchange.export.ExportParameters');
const GeometricalFormat=Java.type('com.technia.dsx.exchange.export.GeometricalFormat');
const EngItemMask=Java.type('com.technia.dsx.threedspace.eng.item.EngItemMask');
const EngItemField=Java.type('com.technia.dsx.threedspace.eng.item.EngItemField');
Then in your config, you then can do like:
//@include:DSXAPI.js
const itemId = context.jobRequestMessage().sourceEvent().objectId();
const spaceService = context.dsxAPI().getSpaceService();
const session = context.dsxAPI().getTenantSession(spaceService);
const item = spaceService.getEngItemService().read(session, itemId, EngItemMask.DETAILS);
const attributes = item.getAttributes();