Process Designer Script Reference
-
1 month ago #64233
Hello,
is there somewhere a Scripting Refference on how to
access Widget Values and Global Variables?Some snippets found here likesap.ui.getCore().byId(“ScreenId–WidgetId”).value
don’t work for me.I could export the Project and look on at the code. Now I see how to access the variables and Widget Values.
Read Global Variable:
this.getGlobals().getVar("variableName");
Set Global Variable:
this.getGlobals().setVar("name", val);
Read Widget Value:
this.getItemValue("screen", "item", "property");
Also can be found as Code Snippet in the Script Editor. Search for Set/Get
What I did not found is how I can acces or write in Global Variables structs.
Regards Gergey
-
This topic was modified 3 weeks, 5 days ago by
Gergey Matl.
Armin Winkler
ModeratorHas successfully completed the online course Introduction
Has successfully completed the online course Intermediate (200)
Has successfully completed the online course Advanced (300)
Has successfully completed the online course Basics (100)
3 weeks, 1 day ago #64392::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 3 weeks, 1 day ago by
Armin Winkler.
Attachments:
You must be logged in to view attached files.Vitali Kurdasov
ModeratorHas successfully completed the online course Intermediate (200)
Has successfully completed the online course Basics (100)
Has successfully completed the online course Advanced (310)
Has successfully completed the Intermediate Certification
3 weeks, 3 days ago #64347::Hi Gergey Matl,
you can set a whole struct as a globals variable by using this.getGlobals().setVar(‘VarName’,obj);
If you want to change just one property i would suggest you to use the setProperty Method:
sap.ui.getCore().getModel(‘variableHolder’).setProperty(‘/VarName/PropertyName’, value);
Of course you can use getProperty() aswell to read the Variable afterwards.
-
This topic was modified 3 weeks, 5 days ago by
You must be logged in to reply to this topic.