0

I have a JavaScript transformation where I take a csv and load it into db using MLCP. Say that my function accepts content and context. I have 2 other parameters that I need to pass through MLCP so that I can use it in the transformation. Can I use -transform_param "my-value" in this case? How do I write the function?

I am hard coding the values as of now instead of passing them as a parameter.

function test(content, context, param1, param2)
{
//use param1 and param2
}
//export

Is this the right implementation?

Expectation: Use the transformation to use on other documents. Reality: Hard coding the values to be used.

Mehul
  • 148
  • 9

1 Answers1

2

Check this example.

The context variable should contain your parameter.

function yourTransformation(content, context)
{
  const propVal = (context.transform_param == undefined)
                 ? "UNDEFINED" : context.transform_param;

  ...
};
Wagner Michael
  • 2,172
  • 1
  • 15
  • 29
  • I'm passing transform_param the value that I want to give to propVal. In my transformation I have "var colA = newDoc.propVal" and then I am using my colA in URI. It's still not working. Where am I going wrong? – Mehul Apr 17 '19 at 09:24
  • Could you please post the code of your transformation? – Wagner Michael Apr 17 '19 at 12:26
  • I've fixed it using the function call in the transformation and passing the parameters there for now. – Mehul Apr 25 '19 at 06:29