As a newbie I am still finding my way around scripting.
I have a drop down box which displays as Null and has a drop down list of two values (“Action Required” and “No Action”).
If I am changing the list from the Null value to any of the other values I want to ammend some fields on another form. If I am changing from anything other than the Null value I don’t want to make any changes to the corresponding form.
I have created the scrip below and am using the “ChangeData” event
However, I cannot capture the “null” value because the timing of the Change Data event seems to be after the datachange, rather than capture the information prior to the change. Therefore, on the current scrip the changes take place on the corresponding form every time I change the dropdown value instead of just when I change the list from Null.
Is there a way around this?
var dropDownChange = email_to_actionid.actionornot
application.output (dropDownChange);
if (dropDownChange = ‘null’ )
{
//look for matching record in the actions form based on emailid in the current form
var emailID = emailid;
application.output (emailID)
forms.actions.controller.find();
forms.actions.emailid = emailID;
forms.actions.controller.search();
//set actiontrigger, compnanyid, actionrequired fields in the matching record of the actions form.
forms.actions.controller.setDataProviderValue(‘actiontrigger’,‘email’); //action trigger is created from email
forms.actions.controller.setDataProviderValue(‘actionrequired’,‘See Email ID’ + emailID );
//remove the foundset
forms.actions.controller.loadAllRecords()
You must literally use arguments[0]. That’s the argument passed by Servoy into a method on an onDataChange event - that contains the old value of the field.
var oldValue = arguments[0]
if(!oldValue)
{
//oldValue was null or empty
//YOUR CODE HERE
}
else
{
//oldValue was NOT null or empty
//YOUR CODE HERE
}
Many thanks - that makes it clear. I struggled to find the relevant info in the documention as a search on “arguments” brings up alot of hits. Is there a particular section I should be looking at in the manual for background on this?
What I was confused about was why argument [0] refers to a previous value when using the onDataChange event. I can’t see any reference to this in the manual.
I can identify with the struggle to learn the components of javascript, and to figure out how to apply them within a Servoy solution. There is a lot to javascripting and the “whole enchillada” could never be included in the Servoy Documentation.
A search in Acrobat on the Servoy Developer manuals goes pretty quickly. For example, you can search for “arguments[0]” and determine pretty quickly that this string is not explicitly explained therein. What I’ve been doing as my next strategy is to Google the phrase. (What the heck did we ever do before Google?!). There is so much information, and so many tutorials, on javascript out on the Web it will boggle your mind. The problem is twofold: (1) your Google hit-list will likely be so long it is a challenge to sift through it, and (2) almost paradoxically, javascript components can, it seems, be “mixed ‘n’ matched” so many ways when you are writing your functions, that - in spite of all those Google hits and tutorials - it might be hard to find an exact answer to your question. But gradually one begins to assimilate and process all that info so that one starts to “get it”.
I have also found it very helpful to keep a couple of books around on javascripting. Just about everything in a javascript will apply to using it in Servoy solutions (except, as I understand it anyhow, the document and window classes).
Here is what I’ve learned from my explorations regarding this arguments[0] thingie:
‘arguments’ is an array of values that is passed to a function
javascript starts counting at 0, so the first value in an array is numbered 0
when you use ‘arguments[0]’ you are telling the function to evaluate (or return) the first value that was passed to it
the old value of a field is passed through when you use the onDataChange event … therefore arguments[0] will recall that value for further action in the method you have called
There may well be instances of non-standard vocabulary in my description, but I’m hoping that coming from another beginner javascripter, and therefore in “Beginner Javascripter Speak”, maybe it helps?