Can I write a custom expression engine function for use in a canonical transform expression?


#1

I know I can write a entire custom transform function, but what if only one of the field transform expressions is complex?

Can I do something like this?

type MyCanonicalTransformType mixes MyDestinationType transforms MyCanonicalType {
  id: ~ expression 'id'
  parent: ~ expression '{"id": parentId}'
  description: ~ expression 'transformDescription(canonicalDescription)'
  transformDescription: function(canonicalDescription: string) : string js server
}

and implement transformDescription in a JavaScript source file:

function transformDescription(canonicalDescription) {
  var result;
  
  // Complex logic here

  return result;
}

My use case is a remix of an existing canonical transform type (implemented with expression-based transforms). One field’s transform needs to be implemented in JavaScript, but I would like to avoid having to duplicate the entire transform.


#2

Hi @matt, have you found an answer to this question?


#3

@lerela Not at this time, but this feature is on the roadmap


#4

Now that saw this (after writing one custom EEF for canonical transformation), I need help: How can one split a string and then take n-th element of the result, using expressions only? There is function split, but then…


#5

Split returns an array of string, so you can get the [n-th] element.

Here’s an example of an expression in a transform:

failureType: ~ expression {id: "split(slot, '_')[1]"}


#6

Thanks, tried something like this (0 instead of 1) but got a syntax error.


#7

Actually, after some more changes, it worked, thanks!


#8

Has the feature mentioned by the OP been implemented - invoke a method on a field in the transform type?