run trigger when the date is met

Posted by clga29261 on 08-Apr-2015 01:11

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

Posted by Godfrey Sorita on 08-Apr-2015 08:25

Hi Marcelo,

You want to run a trigger when the current date falls on a cutoff date? Is this your question?


Regards,
Godfrey

Posted by clga29261 on 09-Apr-2015 23:01

Exactly sir..

[collapse]
On 8 April 2015 at 21:26, Godfrey Sorita <bounce-gsorita@community.progress.com> wrote:
Reply by Godfrey Sorita
Hi Marcelo,

You want to run a trigger when the current date falls on a cutoff date? Is this your question?


Regards,
Godfrey
Stop receiving emails on this subject.

Flag this post as spam/abuse.


[/collapse]

Posted by clga29261 on 09-Apr-2015 23:02

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

Thanks,


[collapse]
On 10 April 2015 at 12:01, Marcelo S Cantong II <clhe122110@gmail.com> wrote:
Exactly sir..

[collapse]
On 8 April 2015 at 21:26, Godfrey Sorita <bounce-gsorita@community.progress.com> wrote:
Reply by Godfrey Sorita
Hi Marcelo,

You want to run a trigger when the current date falls on a cutoff date? Is this your question?


Regards,
Godfrey
Stop receiving emails on this subject.

Flag this post as spam/abuse.



[/collapse][/collapse]

Posted by Pradeep Kagithalagudem on 10-Apr-2015 03:39

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

Posted by clga29261 on 10-Apr-2015 03:53

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.. ;-)

[collapse]
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.


[/collapse]

Posted by Anoop Premachandran on 10-Apr-2015 06:55

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.

Posted by Godfrey Sorita on 10-Apr-2015 07:58

[quote user="clga29261"]

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

[/quote]

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
}

Posted by clga29261 on 10-Apr-2015 20:14

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

[collapse]
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.


[/collapse]

Posted by Godfrey Sorita on 13-Apr-2015 09:30

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

Posted by clga29261 on 13-Apr-2015 21:07

how can i convert this 

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

into date..

because, it cant save to create record..


thanks,
celo

[collapse]
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.


[/collapse]

Posted by Godfrey Sorita on 14-Apr-2015 07:37

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);


Posted by spope-rollbase on 17-Apr-2015 02:20

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..

Posted by spope-rollbase on 17-Apr-2015 03:04

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'};

This thread is closed