run trigger when the date is met - Forum - Rollbase - Progress Community

run trigger when the date is met

 Forum

run trigger when the date is met

This question is not answered

i created cut off setup Period. example, 

january first cut off Period(start date is 1 and end date is 15).

january second cut off Period(start date is 16 and end date is 30).

february first cut off Period(start date is 1 and end date is 15).'

february second cut off Period(start date is 16 and end date is 28).

march first cut off Period(start date is 1 and end date is 15).

march second cut off Period(start date is 16 and end date is 30).

april first cut off Period(start date is 1 and end date is 15).

april second cut off Period(start date is 16 and end date is 30).



these setup is created early this year.

may question is, when the current date and current month is met the start date and month of any cut off periiod. it automatically create a cut off transactions record.

THanks,

All Replies
  • You can use  "Create New Record trigger" for your case. You can use trigger condition formula to evaluate if current date matches or falls below the cut off period. Use recursion option to run this trigger every day or week or month.

    Please see this link for details documentation.progress.com/.../RB_User_Guide.pdf

  • i guess when you use  "Create New Record trigger", you need conversion map. but i my set up in cut off is created ahead of time. like for example.. we have 12months, each month has 2 cut off. those 24 record in set up created earlier..

    example: May First Cut Off: May 1-15. May Second Cut Off: 16-30.. when the current date is equal to May 1, it can create a cutoff transcation. not fall under May 1-15.. 

    I hope you get my point. thanks very much for your concern.. ;-)

    On 10 April 2015 at 16:40, Pradeep Kagithalagudem <bounce-pkagitha@community.progress.com> wrote:
    Reply by Pradeep Kagithalagudem

    You can use  "Create New Record trigger" for your case. You can use trigger condition formula to evaluate if current date matches or falls below the cut off period. Use recursion option to run this trigger every day or week or month.

    Please see this link for details documentation.progress.com/.../RB_User_Guide.pdf

    Stop receiving emails on this subject.

    Flag this post as spam/abuse.


  • What you can do is the following. (Workaround)

    1. Create an Object. Lets call it  "Cron Job"

    2. Make sure it has one record with Name "Date based Cutoff Trigger"

    3. Now Create a Data Maintenance Batch Job for this Object and make sure it is set to repeat every Day/Week/Month" as needed.

    4. Now in "Object Script" of this job, you can write your cut off logic.

    5. You can make sure your logic is run only if current record Name is "Date based Cutoff Trigger" thus avoiding multiple runs if someone creates another entry for your "Cron Job"

    6. You can use this to add more such jobs in future.

  • clga29261
    If the current date is equal to the start date of that Cut off, if will run a trigger.

    Here's a sample batch job code for your reference:

    var currentDate = new Date();
    var cutoffDate = new Date("{!Cutoff_Date}");
    
    rbv_api.println("CurrentDate:"+ currentDate);
    rbv_api.println("CurrentDate:"+ new Date(currentDate.setHours(0,0,0,0)));
    rbv_api.println("cutoffDate:"+ cutoffDate);
    rbv_api.println("cutoffDate:"+ new Date(cutoffDate.setHours(0,0,0,0)));
    if (currentDate.setHours(0,0,0,0) == cutoffDate.setHours(0,0,0,0)) {
    	//Execute code here
    }

  • my logic condition if the current date is equal to the start date of cutoff month is in the trigger inside the object, then i have batch jobs where in the script is runtrigger.. do you think it will work???

    or, i will put my logic condition in batch jobs object script? when the condition is true, it call to run the trigger inside my object wherein that trigger create a record..

    correct me if im wrong.. thanks.,. ill post my code now..

    THE CODE OF TRIGGER INSIDE THE MY OBJECT
    var today = new Date('#EVAL[return rbv_api.getCurrentDate()]');
    var preDate = today.getDate();
    var preMonth = today.getMonth()+1;
    var preYear = today.getFullYear();

    var scodeOfMonth = rbv_api.getCodeById('cut_off_period1', 'start_month_cutoff_period', {!start_month_cutoff_period#id});
    var scodeOfDate = rbv_api.getValueById('cut_off_period1', 'start_date_cutoff_period', {!start_date_cutoff_period#id});
    var ecodeOfMonth = rbv_api.getCodeById('cut_off_period1', 'end_month_cutoff_period', {!end_month_cutoff_period#id});
    var ecodeOfDate = rbv_api.getValueById('cut_off_period1', 'end_date_cutoff_period', {!end_date_cutoff_period#id});

    var svalueOfMonth = rbv_api.getValueById('cut_off_period1', 'start_month_cutoff_period', {!start_month_cutoff_period#id});
    var evalueOfMonth = rbv_api.getValueById('cut_off_period1', 'end_month_cutoff_period', {!end_month_cutoff_period#id});

    var fromCut = new Date(svalueOfMonth+' '+scodeOfDate+', '+preYear);
    var toCut = new Date(evalueOfMonth+' '+ecodeOfDate+', '+preYear);

    if ((scodeOfMonth == preMonth) && (scodeOfDate == preDate)){
    var arrCodeOfDate = new Array();
    arrCodeOfDate['cut_off_from_trans'] = fromCut;
    arrCodeOfDate['cut_off_to_trans'] = toCut;
    arrCodeOfDate['R3565703'] = 'Regular';
    rbv_api.createRecord('cut_off_transaction', arrCodeOfDate);
    rbv_api.printArr(arrCodeOfDate);
    }

    THE CODE SCRIPT INSIDE MY BATCH JOB
    rbv_api.runTrigger("cut_off_period1", Number({!id}), "createCutOffTrans", false);



    c

    On 10 April 2015 at 20:58, Godfrey Sorita <bounce-gsorita@community.progress.com> wrote:
    Reply by Godfrey Sorita

    clga29261
    If the current date is equal to the start date of that Cut off, if will run a trigger.

    Here's a sample batch job code for your reference:

    var currentDate = new Date();
    var cutoffDate = new Date("{!Cutoff_Date}");
    
    rbv_api.println("CurrentDate:"+ currentDate);
    rbv_api.println("CurrentDate:"+ new Date(currentDate.setHours(0,0,0,0)));
    rbv_api.println("cutoffDate:"+ cutoffDate);
    rbv_api.println("cutoffDate:"+ new Date(cutoffDate.setHours(0,0,0,0)));
    if (currentDate.setHours(0,0,0,0) == cutoffDate.setHours(0,0,0,0)) {
    	//Execute code here
    }

    Stop receiving emails on this subject.

    Flag this post as spam/abuse.


  • The code looks good! BTW, you can check the value of JavaScript variables using rbv_api.println().
  • how can i convert this 

    var fromCut = new Date(svalueOfMonth+' '+scodeOfDate+', '+preYear);  

    into date..

    because, it cant save to create record..


    thanks,
    celo

    On 13 April 2015 at 22:30, Godfrey Sorita <bounce-gsorita@community.progress.com> wrote:
    Reply by Godfrey Sorita
    The code looks good! BTW, you can check the value of JavaScript variables using rbv_api.println().
    Stop receiving emails on this subject.

    Flag this post as spam/abuse.


  • As mentioned in my previous comment, you can use rbv_api.println() to debug the code.

    var fromCut = new Date(svalueOfMonth+' '+scodeOfDate+', '+preYear); 
    rbv_api.println("Year:"+ preYear);
    rbv_api.println("Day:"+ scodeOfDate);
    rbv_api.println("Month:"+ svalueOfMonth);
    rbv_api.println("Date:"+ fromCut);


  • You need to add .getTime() to your dates..

    arrCodeOfDate['cut_off_from_trans'] = fromCut.getTime();

    arrCodeOfDate['cut_off_to_trans'] = toCut();

    (Sorted this same issue out with Dates yesterday..)

    Buried on p828 of the current User Guide documentation:

    As the return type of a formula: return the full value of the JavaScript getTime() method.

    For example:

    return myDate.getTime();

    Hope this helps..

  • fyi:

    var x = new Array();

    x["amount"]=1000;

    x["R477842"]={!id};

    x["name"]="API Created";

    The Javascript  recommended way is the following:

    var x = {amount : 1000 , R477842 : {!id} , name : “API Created”};

    In your case:

    var arrCodeOfDate = {cut_off_from_trans:fromCut.getTime(), cut_off_to_trans:toCut.getTime(), R3565703:'Regular'};