Vlocity Facts #40 || Using Custom Function in DataMapper

If we can't find the formulae or functions in Data Mapper's formula tab. Create new apex class containing the needed logic, which can be invoked in DataMapper by using Function().
If we need to call a apex class from omnistudio we need to follow these steps

  • Apex Class should be global with sharing to follow all the sharing settings.
  • The Apex Class must implement the Callable interface.
  • You must override the invokeMethod, which takes the following parameters
  1.  String methodName
  2.  Map<String, Object> input
  3.  Map<String, Object> output
  4.  Map<String, Object> option
  5. Try to use try and catch block.
  6. Then check the methodName and call that method by passing all the parameters.

Consider this scenario, we can find the datediff between two dates in DataMapper by using this formula
DATEDIFF(date1, date2) --> DATEDIFF(%DOB%,%TODAY%)
To find the difference between two datetime fields we don't have standard formula or function in Omnistudio in this case we need to implement 'Custom Function' by using apex class and Function() in DataMapper.

Maintain the "call" method as it is illustrated below. It will call the "invokeMethod" function.
In DataMapper formula tab you can use Function()
FUNCTION('apexClassName','methodName',%Input%)
To call the above apex class -->
FUNCTION('dateTimeDiffFinder','calculateDateTimeDifference',%CaseId%)
Passing CaseId as the input and displaying the ClosedDate of the case by using query for reference and passing same CasedId to apex class and calculating the DateTime Difference between NOW() and ClosedDate of the case record.
Result: 
The value we are getting in DateTimeDifference node is difference between the NOW() and ClosedDate is in minutes.




Comments

Popular posts from this blog

Vlocity Facts #01 | OmniStudio DataRaptors

Vlocity Facts #34 || Getting the details from the URL in a FlexCard and an Omniscript

Vlocity Facts #44 || Communication between Omniscript and Flexcard [Pub/Sub]