Saturday, August 14, 2010

Date Calculations in eScripting

Date addition and subtraction can be easily done using the following methods of Date Object.

1. setDate() / getDate()
2. setMonth() / getMonth()
3. setYear() / getYear()
4. setFullYear() / getFullYear()

Any Siebel date field can be easily converted to date object using the following date constructor statement. For eg.

var dtOptyDate = new Date(GetFieldValue("Created"));

Now you can use the above mentioned methods on this date object to perform date calculation. 

For example if you want to add an year to the Created Date and update automatically in committed date you can write the script as follows

dtOptyDate.setFullYear(dtOptyDate.getFullYear() + 1)

or alternatively

dtOptyDate.setMonth(dtOptyDate.getMonth() + 12)

Beauty of this it will automatically take care of the Leap year / 30 and 31 days calculations for the respective months etc....

Once you have calculated the date then you need to set the same back in Siebel field as follows

SetFieldValue("Oppty Due Date",  ((dOptyDate.getMonth() + 1) + "/"" + dOptyDate.getDate() + "/" + doptyDate.getFullYear()));

No comments:

Post a Comment