- OnChange - change date
- Posted by Harm Vestjens on July 12th, 2006
I'm looking for an OnChange script to generate a date in a certain field.
The issue : I have a picklist of three items; '1 year', '2 year' and '3 year'.
This is field "term"
The datefield is called "startdate"
I want to generate a field called "renewaldate", what has to be generated of
"date" + "term".
I'm not a scripter, but I am learning
With the upper script I would
certainly understand the scriptlanguage.
- Posted by Michael Höhne on July 12th, 2006
This should help you to get started:
var years = 0;
switch(crmForm.all.new_term.DataValue) {
//You need to check the picklist values if they have the values 1, 2 and
3. Look at the attribute in the entity customization and note the option
values.
case "1":
years = 1;
break;
case "2":
years = 2;
break;
case "3":
years = 3;
break;
}
if (years != 0) {
var date = new Date();
date.setYear(date.getYear() + years);
crmForm.all.new_startdate.DataValue = date;
}
--
Michael
http://www.stunnware.com/crm
----------------------------------------------------------
"Harm Vestjens" <HarmVestjens@discussions.microsoft.com> schrieb im
Newsbeitrag news:3774BD1E-CA17-47A4-AAC7-2E40D8BBBDBB@microsoft.com...
- Posted by Harm Vestjens on July 18th, 2006
Thankz for your reaction!
Let me give some more details:
I have a form where we can save domain information.
A domain is registered at a certain data ('regdate')
A domain has a registration term ('regterm')
The next step in this form is when I select the date in 'regdate' and after
this select the term in 'regterm' an other field has to generate the renewal
date 'renewaldate'.
I'm not a scripter, so please help me with this.
Things I allready have made - a data field (regdate) and a picklist (regterm)
What kind of field is the 'renewaldate' and WHERE do I put the script? Is it
a field script? Or form script? Is it a OnChange or OnLoad? Do I need to
create a new relation?
On 12-7-2006 22:43:14, "Michael Höhne" wrote:
- Posted by Michael Höhne on July 18th, 2006
Your renewaldate field will be a date field and you need to place the code
in the OnChange event scripts of the other fields (regdate and regterm). As
the renewaldate can only be calculated after these fields have been
populated, the OnChange script will be similar to the following:
if ((crmForm.all.regdate.DataValue != null) &&
(crmForm.all.regterm.DataValue != null)) {
var years = 0;
switch(crmForm.all.new_term.DataValue) {
//You need to check the picklist values if they have the values 1, 2 and 3.
Look at the attribute in the entity customization and note the option
values.
case "1":
years = 1;
break;
case "2":
years = 2;
break;
case "3":
years = 3;
break;
}
if (years != 0) {
var date = crmForm.all.regdate.DataValue;
date.setYear(date.getYear() + years);
crmForm.all.renewaldate.DataValue = date;
}
}
--
Michael
http://www.stunnware.com/crm2
----------------------------------------------------------
"Harm Vestjens" <info@veon.nl> schrieb im Newsbeitrag
news:OTjG6cmqGHA.956@TK2MSFTNGP03.phx.gbl...
- Posted by Harm Vestjens on July 28th, 2006
Yes ! It worked.
The next step is... besides years we also have months...
"Michael Höhne" wrote:
- Posted by Nico de Lezenne Coulander on November 23rd, 2006
Hello Michael,
Refering to the question Harm Vestjens asked: is it possible to use the
"crmForm.all.renewaldate.FireOnChange" in both the "OnChange" events of the
'regdate' and the 'regterm' fields, and place the code in the
"renewaldate.OnChange" event?
Otherwise you have to place the SAME code in both "OnChange"-events?
Nico
"Michael Höhne" wrote:
- Posted by Michael Höhne on November 24th, 2006
You can call FireOnChange wherever you want. However if your code becomes
more complex, you may try another approach: define global methods and
variables. It's described here:
http://www.stunnware.com/crm2/topic.aspx?id=JS5
--
Michael
Web: http://www.stunnware.com/crm2
Feed: http://www.stunnware.com/crm2/atom.aspx
----------------------------------------------------------
"Nico de Lezenne Coulander"
<NicodeLezenneCoulander@discussions.microsoft.com> schrieb im Newsbeitrag
news:9808167D-FC41-4D47-83F3-F597BA25C741@microsoft.com...