cancel
Showing results for 
Search instead for 
Did you mean: 

Personas onChange Event Value

eedens
Participant
0 Kudos

This post from 2018 refers to the same issue I'm seeing. Is there a way to get the new value of a text field when using the onChange script event? The source.text value the event returns is the old value, which for field validation isn't really useful.

Accepted Solutions (1)

Accepted Solutions (1)

Damean
Active Contributor

Hmm ... It actually works for me (I'm in Per 3, SP10). The magic is using the combo of "OnChange" event and the event variable "newValue" Here's a sample instruction:

1) On transaction MM03 (Material Display field); insert a Script to the "onChange" event of material master field

2) The script sample as below

var zdc_input = newValue;

session.utils.alert("New Value--" + zdc_input);

3) Now, try the following by entering a value into the MM03 material master field, then press "Tab" -> The popup will now appear.

HTH

eedens
Participant

Thanks damean-bf.chen, bwills, and cristiano.hansen! The magic was the newValue variable i.e. console.log(newValue). I'd been trying variations of source.text based on the scripting help popup:

Limitations:WIN:future, HTML:7.53.
The event is triggered only if the text field's value has changed and it loses its focus or any key that triggers a roundtrip such as enter or a function key is pressed while the cell still holds the focus. Note that this event is not fired when an F4 help popup window is closed and the field value has changed as a result of the F4 help interaction.
The event is not suppressible. This means that if a handler script navigates to some other transaction it must return to the screen from where the onChange event was fired (otherwise there will be a backend error).
Reading the text field's text property (accessible through 'source.text') within the onChange handler script yields different results depending on GUI type (SAP GUI for HTML, Windows or Java). In one GUI this may be the old value, in another it may be the new value.
The onChange script can manipulate the text field's value e.g. with the corrected value by setting the text property of the control (either through "source.text" or "session.findById('<field id>').text").

Answers (2)

Answers (2)

bwills
Contributor

Hi Elliott,

Here is the solution. When you look at the onChange event in the inspector it says:

It passes variables: source, oldValue and newValue.

You just need to use the variables. So create a script for the onChange event for the GuiTextField. Here is a snippet of code.

session.utils.log("onChange");

session.utils.log('oldValue =>' + oldValue);
session.utils.log('newValue =>' + newValue);

Every time you change the textfield value it displays the oldValue and newValue as expected. Easy as that. Hope this helps. FYI I'm using Personas 3.0 SP11.

Cheers,

Brian

cris_hansen
Advisor
Advisor

Hi Elliott,

Even this question/answer shows no solution.

I give it a try in my system with SP12 + latest version of the client note: it doesn't work.

I suggest raising a SAP Support incident under BC-PER, so the development team can be involved.

Regards,

Cris