why do we keep Script & Text both in Output Parameters
what is the purpose of Script dataType in Camunda modeller ?
Here is an example:
Note that outputVarName is the value of offerprice Script.
why do we keep Script & Text both in Output Parameters
what is the purpose of Script dataType in Camunda modeller ?
Here is an example:
Note that outputVarName is the value of offerprice Script.
For me, the script is one of the most used type in input output mappings, because I can create Objects of any kind easily, at least easier than filling maps and lists, and itās much more powerful. These objects can be used by other components without any problem.
Iām not sure if offerprices script is evaluated before beeing assigned to the Text Variable outputVarName, so I never use input or output mapping in this way.
My confusion is when we should be using Script type and when Text type ? any example please.
A script is a output type with a name because scripts last executed functions are returned. Example in JavaScript if you just wrote 2+2 then that eval would be returned.
A script does not need to return something, so you have options. Think of scripts as a way to manipulate data and preform actions.
An example:
Suppose you have to pass the output variable as a calculated map to the rest of the execution.
Output Var Name: āmyMapā
Output Var Type : āScriptā
script type: āgroovyā
body:
return [ city: [ name: city_name, country: city_country ], products: listProducts1.addAll(listProducts2), ]
This script will save in myMap an map of objects (a list and a map in this case)
You can use this object as you wish in other following scripts/juel expression or java delegates.
For example for an expression :
${myService.processAndSave(myMap)}
or
${myService.saveProduct(myMap.products)}
But this is an example. The possibilities are endless.
You are using āgroovyā. Do you need to return in grovy script ? I dont know grrovy .I know javascript.
Say , I write these ā¦
Name: outputVar
Type: Script ,
Script Format : Javascript .
Script Type: Inline script
Script
var inData = execution.getVariable(āinputDataā);
var someOtherVar= JSON.parse(productType);
what will be returned ?
Is it the only the last variable i.e someOtherVar or both ?
You said ā¦
Does this mean only last executed part i.e someOtherVar will be returned here ?
Please correct me if Iām wrong.
@cofactor, You can do a lot of things. As a groovy script, I donāt know if it works for others, you can return a variable using āreturn varNameā or simply using āvarNameā as the last line of the script.
Like you said, the last line of code will be the returning value, but if you put
varName = āsome Valueā
this line will return null, because itās an assignment. In groovy this will return the variable itself, so it should work, but I donāt guarantee in other languages. You should do something like one of these:
varName = āsome Valueā
varName
OR
āsome Valueā
OR
return āsome Valueā
OR
varName = āsome Valueā
return varName
You can also return null and set some execution variables (maybe you donāt use a script for input mapping without a returning value, but theoretically you can).
That was very much helpful.
you would do:
var inData = execution.getVariable(āinputDataā);
var someOtherVar= JSON.parse(productType);
someOtherVar;
Where line 3 is the return final value. But you do not need to do this in every case. often you are wrapping all of your code in āfunctionsā and thus you are using execution.setVariable() rather than the final returned value.