Wiki source code of Groovy Script

Last modified by Erik Bakker on 2024/09/05 13:53

Show last authors
1 {{container}}{{container layoutStyle="columns"}}(((
2 In this microlearning, we’ll explore how to leverage Groovy scripts within the eMagiz platform to extend its functionality beyond the standard components available in the flow designer. Groovy scripts offer powerful customization options for situations where the default tools fall short. We’ll discuss where and how to implement Groovy scripts, including their use in filters, transformations, and executors. Key considerations include understanding their complexity, managing dependencies, and ensuring proper documentation. This guide will help you make informed decisions about using Groovy scripts effectively and responsibly.
3
4 Should you have any questions, please get in touch with [[academy@emagiz.com>>mailto:academy@emagiz.com]].
5
6 == 1. Prerequisites ==
7
8 * Expert knowledge of the eMagiz platform
9
10 == 2. Key concepts ==
11
12 This microlearning focuses on groovy scripts. A groovy script is a piece of code written in the groovy language that allows you to extend the platform's functionality beyond the mere use of the components supplied via the flow designer.
13
14 * Groovy scripts should be viewed as an extension that can be used in fringe cases, not as a standard best practice
15 * When a groovy script becomes so complex that you are programming, you should consider alternatives to the solution
16 * Groovy scripts can be used in a filter, transformation, and as part of a standard executor
17 * Groovy scripts should be well documented as they are though to read for most of our community members
18 * There is no guarantee from eMagiz that Groovy scripts within models keep working in newer versions of the platform
19
20 == 3. Groovy script ==
21
22 In a low-code platform like eMagiz, you want to prevent using custom scripting as much as possible. However, sometimes in practice, you encounter situations that cannot be realized with the standard toolbox provided within the platform. As a result, we offer the option to use a Groovy script in these situations to achieve the desired solution. In this microlearning, we will look at where you can use a Groovy script and discuss the key considerations when implementing a Groovy script within your model.
23
24 === 3.1 Implementation in Create ===
25
26 To implement a groovy script in Create, you first need to consider what your Groovy script should do. Then, within the flow designer, there are five components available that can handle a Groovy script.
27
28 * In case you want the Groovy script to filter out messages, you should implement the Groovy script in a "standard filter" component.
29 * If you want your Groovy script to always transform your message from a certain format into another format, you should consider using a "standard transformer" component.
30 * The "standard service activator" is your friend if you need an optional output. So, for example, when you want to do some transformation and check whether a message can continue, you can use the "standard service activator" and have an optional output.
31 * When you want to split your message based on a Groovy script, you should use the "standard splitter."
32 * If you want to route messages based on a Groovy script, you should use the "standard router."
33
34 {{warning}}Note that in practice, we mainly see use cases for the "standard service activator" and the "standard transformation." {{/warning}}
35
36 [[image:Main.Images.Microlearning.WebHome@expert-data-handling-groovy-script-available-components.png]]
37
38 Regardless of the component you choose, you always need to select the "Groovy script" option and reference the Groovy resource available on the flow level you want to use within the component.
39
40 [[image:Main.Images.Microlearning.WebHome@expert-data-handling-groovy-script-groovy-configuration.png]]
41
42 {{info}}As you can see in the help text when selecting the "resource" attribute, you need to make sure that the Groovy script is uploaded within the context of your flow.{{/info}}
43
44 After you have the component in such a way that the correct Groovy script is called, you are done with the component's configuration and can test the flow using flow testing.
45
46 === 3.2 Key considerations ===
47
48 * To make some groovy scripts work, you need to upload (third-party) Java libraries that are not packaged on default by eMagiz
49 * To make some groovy scripts work, you need to reference Java libraries via a standard header enricher or as a dummy variable
50 * The store consists of several groovy scripts that might be of use to you
51 * Groovy scripts should be viewed as an extension that can be used in fringe cases, not as a standard best practice
52 * When a groovy script becomes so complex that you are programming, you should consider alternatives to the solution
53 * Groovy scripts can be used in a filter, transformation, and as part of a standard executor
54 * Groovy scripts should be well documented as they are though to read for most of our community members
55 * There is no guarantee from eMagiz that Groovy scripts within models keep working in newer versions of the platform
56
57 == 4. Key takeaways ==
58
59 * To make some groovy scripts work, you need to upload (third-party) Java libraries that are not packaged on default by eMagiz
60 * To make some groovy scripts work, you need to reference Java libraries via a standard header enricher or as a dummy variable
61 * The store consists of several groovy scripts that might be of use to you
62 * Groovy scripts should be viewed as an extension that can be used in fringe cases, not as a standard best practice
63 * When a groovy script becomes so complex that you are programming, you should consider alternatives to the solution
64 * Groovy scripts can be used in a filter, transformation, and as part of a standard executor
65 * Groovy scripts should be well documented as they are though to read for most of our community members
66 * There is no guarantee from eMagiz that Groovy scripts within models keep working in newer versions of the platform
67
68 == 5. Suggested Additional Readings ==
69
70 * [[RCA Knowledge Base (Menu)>>doc:Main.eMagiz Support.RCA Knowledge Base.WebHome||target="blank"]]
71 ** [[Configuration Issues (Navigation)>>doc:Main.eMagiz Support.RCA Knowledge Base.rca-knowledgebase-configuration-issues.WebHome||target="blank"]]
72 *** [[Incorrect Groovy Configuration (Explanation)>>doc:Main.eMagiz Support.RCA Knowledge Base.rca-knowledgebase-configuration-issues.rca-knowledgebase-incorrect-groovy-configuration.WebHome||target="blank"]]
73 * [[Groovy - Explained (External)>>https://www.emagiz.com/features-of-the-platform/||target="blank"]]
74 * [[Groovy (Search Result)>>url:https://docs.emagiz.com/bin/view/Main/Search?sort=score&sortOrder=desc&highlight=true&facet=true&r=1&f_space_facet=0%2FMain.&f_type=DOCUMENT&f_locale=en&f_locale=&f_locale=en&text=groovy||target="blank"]]
75
76 )))((({{toc/}}))){{/container}}{{/container}}