Business workflow & Scripting API
Header
Level: Intermediate
Keywords: business, workflow, scriptingAPI
The result: checking and switching states using ScriptingAPI
Check entity state​
In the following example, the ScriptingAPI is used to determine the state of the entity from the context.
get entity state example
var ref = {
type : "ft_defDefectLighting",
id : "335018862826394390052151173600"
};
var currentState = api.business()
.prepareGetEntityState(context)
.entityRef(ref)
.get();
api.debug()
.prepareOutput()
.withDelimiter()
.message("entityState")
.addVariable("isStateSet", currentState.isStateSet())
.addVariable("getStateKey", currentState.getStateKey())
.addVariable("getStateTitle", currentState.getStateTitle())
.addVariable("getStateCode", currentState.getStateCode())
.addValue(getStateCode.getStateCode())
.print();
Check entity state​
In the following example, the ScriptingAPI is used to swith the entity from the context to the new state.
change entity state example
var ref = {
type : "ft_defDefectLighting",
id : "335018862826394390052151173600"
};
api.business()
.prepareChangeEntityState(context)
.entityRef(ref)
.state("closed")
.ifNotAlreadyInState(true)
.change();
Trigger entity instance action​
The following example shows the possibility to invoke an action on instance of another entity.
fire example
api.business()
.prepareTriggerEntityAction(context)
.entityRef(defect)
.action("updateDateDetect")
.requestObject({
updateEntity: {
at_defBoDefect__note: "this is note",
at_defBoDefect__detection_date: new Date().getTime()
}
})
.trigger()