Search code examples
scriptingsiebel

Siebel Business(E-script) Service Calculate Expiry Date


I have a requirement to create a business service function to calculate expiry date , 2 weeks from a date field in Siebel.

I have written the code in Java which is

public static Date checkexpiry(Date Datefield)
    {
     Calendar cal = Calendar.getInstance();
    cal.setTime(Datefield);
    cal.add(Calendar.DATE, -14);
    Date twoWeeksToExpiry = cal.getTime();
    System.out.println(twoWeeksToExpiry);
        return twoWeeksToExpiry;
    }

if current date is equal to twoWeeksToExpiry {do .....}

So how can I re-write this code on Siebel using a business service particularly E-script.

The whole idea is have an output Yes is its 2 weeks before a date field in Siebel.

This will later be used in a work flow.


Solution

  • OK so have started Migrating my Java coding skills to Siebel E-Script I came up with this.

    function ExpiryNotification(Inputs,Outputs)
    {
        try
        {
                var expiryDate = Inputs.GetProperty("DateField");
                var eDate= new Date(expiryDate);
                var notificationdate = eDate-14;
                var currentdate = Today();
    
                if (currentdate==notificationdate){
    
                Outputs.SetProperty("Notification", "Y")
    
                }
    
                else {
                 Outputs.SetProperty("Notification", "N")
                }
    
        catch(e)
        {
            TheApplication().RaiseErrorText(e.toString());
        }
    }
    

    However I did not use the Business Service ..I used a calculated field on my Business Component. The calculated Fields

    1 twoWeeksToExpiry = Datefield-14

    1. Notification = IIf (Today()==[twoWeeksToExpiry], "Y", "N")

    So this solved the problem without scripting,

    Will appreciate any suggestions on my scripting thou I didn't use it.