Hi Gergey,
you can use the ‘Script blocks’ that are included in the toolbar of the code editor as part of a Script activity in the Process Designer (see attachment). By selecting one of the entries from the list, a code snippet will be inserted into the editor which you can then adapt, e.g. by filling in the actual name of a global variable which you want to read. You should find all three of the functions you asked for to read (‘getVar’) and write (‘setVar’) a global variable as well as to access the value of a certain widget property (‘getItemValue’) inside of the list of available script blocks. In addition to Vitali’s previous reply and to address your latest question, I have two more tips for how to use the script functions to your advantage:
- this.getGlobals().getVar() allows you to further navigate into a struct variable and directly read a single field from the data object by using the full path as an argument, here’s an example: this.getGlobals().getVar(‘myStructVariable/fieldName’)
- The same is possible for writing variables if you use the ‘setVar_path’ script block. It will add a third argument to the setVar function which again allows you to overwrite specific fields inside of a data object directly. Code example: this.getGlobals().setVar(‘myStructVariable’, newValue, ‘fieldName’)
Please keep in mind that those script functions aren’t native OpenUI5 code but custom functions available in Simplifier. Those functions are wrappers for the native OpenUI5 methods, so in general it is not a bad idea to use them as they will remain the same in case of an OpenUI5 version update, while the underlying native code might be replaced in a higher version of the library (especially when OpenUI5 1.120 or higher will become the new standard library used in Simplifier). If you still want to make use of the native OpenUI5 methods instead, here’s the reference to them (based on OpenUI5 version 1.96, the current standard library in Simplifier):
- reading a global variable from the standard ‘variableHolder’ model: getProperty; code example: sap.ui.getCore().byId(‘Application’).getModel(‘variableHolder’).getProperty(‘/myVariable’) within the context of an application; sap.ui.getCore().byId(‘myModuleName’).getModel(‘variableHolder’).getProperty(‘/myVariable’) within the context of a Simplifier module
- writing a global variable from the standard ‘variableHolder’ model: setProperty; code example: sap.ui.getCore().byId(‘Application’).getModel(‘variableHolder’).setProperty(‘myVariable’, newValue)
- reading the value of a certain widget property generically: getProperty; code example for reading the property ‘text’ from a ‘Button’ widget: sap.ui.getCore().byId(‘myButton’).getProperty(‘text’)
- reading the value of a certain widget property via dedicated getter method using the example of the Button’s ‘text’ property once again: getText; code example: sap.ui.getCore().byId(‘myButton’).getText()
Hope this helps you! Please let us know should there be uncertainties left on your side.
Kind regards,
Armin
-
This reply was modified 1 month, 3 weeks ago by
Armin Winkler.