cancel
Showing results for 
Search instead for 
Did you mean: 

Action buttons to display orders per specific period - Agentry

Former Member
0 Kudos

Hi;

I am working on SAP Work Manager 6.0 customizing using Agentry 6.1.3. I have these two toolbar buttons that I have created, that is, "Previous Week" and "Next Week". I would like to say, when the use clicks on "Previous week", only Orders for the previous week should be displayed and when they click on "Next Week", only orders of next week should be displayed. By default the current week should be displayed on the device. Would I have to do 3 different fetches to implement this, that is, by default, fetch the current week orders, when the user clicks the "Previous Week" button, do another fetch for that previous week and when they click "Next Week", do the fetch of the orders for next week?!

Please kindly advise as to how best I could implement this?!

Much appreciated!!;

Sizo Ndlovu

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I would suggest having two new values in the Main Object called like:

Z_WeekStart and Z_WeekEnd that hold the start and end date of week selected.

Then have an action that would linked to each button, add or subtract one week.  If you are using Date Time Fields, you will need to add or subtract by 604800, as the time is saved in seconds,

Then in your include rule you would add, a check to see if it greater then the Week Start, and less then the Week End.

Former Member
0 Kudos

Hi Stephen;

Thank you, this a quite a creative solution, tell me, how would I get the WeekStart and WeekEnd dates?

Thanks;

Sizo Ndovu

Former Member
0 Kudos

There is no good way in Agentry, what you can use is a JavaScript Rule.

date - How to get first and last day of the week in JavaScript - Stack Overflow

jason_latko
Advisor
Advisor
0 Kudos

Steve,

Will Agentry translate a javascript returned date to an Agentry format if returned from a sub-rule?  I am not so sure this would work.  Can you provide a working example?

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Jason,

You know that is a good question,  What I was thinking was having a transaction with an initial value rule to set have Javascript return the start (or end) day and then just add or subtract as needed..  One rule for both ways would be needed. 

would that work?

Stephen

jason_latko
Advisor
Advisor
0 Kudos

Steve,

I agree with your premise and it would work, but we would need to figure out how to return a date generated with Javascript in the Agentry integral epoch format.

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

I see Javascript doesnt' return Epoch format because it is going into milliseconds.  So we would need to remove the milliseconds before sending it back to Agentry:
" To get seconds divide by a thousand and round that bugger so we don't get any decimals points."

"var curUnixTime:Date = Math.round(new Date().getTime() / 1000);"

Epoch Time { William Malone }

Former Member
0 Kudos

Hi Stephen, Jason;

Thanks for all the help! Currently the date field that I have coming from the back-end is only a DATE field with no time, would it work to compare this date to the Agentry Epoch time or would I need to bring in a timestamp? Please kindly see my Include rule below:

Note that the WeekEnd and WeekStart properties are of "DATE and TIME" property and the DATE property is of property type "DATE".

I have created 3 transactions, 1 that stamps the date and time to both WeekStart and WeekEnd, another one that adds 604800 to each property, that is, WeekStart and WeekEnd and finally another one that subtracts 604800 from both properties as well. The Initial Value rule I uses is as follows:

The first transaction that stamps the weekstart and weekend properties, with the javascript:

Is my Javascript rule in order?

The 2nd transaction for Adding one week :

I made use of an edit transaction, is this appropriate or I would need an add transaction?

The 3rd transaction that subtracts one week:

And then finally, on the actions sitting on the "Previous Week" and "Next Week" buttons, I put the 1st action step as the transaction for determining the current weekstart and weekend, followed by an applystep and then the 4th step is the transaction that subtracts/adds, followed by an apply.

Currently, when I click on these buttons, the tile list is cleared, I'm thinking it possibly could be my javascript rule or the comparison between the DATE and epoch time.

Please advise?!

Much appreciated!

Sizo Ndlovu

jason_latko
Advisor
Advisor
0 Kudos

Sizo,

Try this on the ATE where you can debug the rules and see their execution at runtime.  That way you can see what is being returned by Javascript and your other date manipulation comparisons.  You may need to create Windows versions of your screens though to test it properly.

Jason Latko - Senior Product Developer at SAP

Answers (2)

Answers (2)

Former Member
0 Kudos

This was a great solution to my requirement, it works perfectly, great idea Stephen Streeter!!!

Thanks;

Sizo Ndlovu

jason_latko
Advisor
Advisor
0 Kudos

Sizo,

How did you get the javascript rules working correctly?  Can you post the solution please?

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Hi Jason;

I was meant to call the javascript function after its definition, see screenshots below:

Below is the rule that calculates the current week start:

The rule to calculate current week end:

The above rules are sitting on the main transaction that first sets the WeekStart and WeekEnd dates. I then have other 2 transactions, one that adds an extra week to the Main Object properties, WeekStart and WeekEnd, as Stephen suggested and one that subtracts a week.

One issue though, the dates that were being calculated by the javascript rules were always giving the correct day, month, but a wrong year, 2045, I do not know why, so I subtract 31 years from that, which is 978264706 epoch time from the final time to get the currect year.

Thanks for all the help.

Regards;

Sizo Ndlovu

Former Member
0 Kudos

Hi;

I'm stuck with the Javascript part of this proposed solution, I have tried different scenarios with no success, when I test the javascript code on a Javascript compiler, it works, but does not pass any values, my javascript rules are returning zero. Some how, there is something that I am missing with the passing of values from the javascript snipper to an Agentry property. Could there possibly be another way of having this requirement implemented in a different way, using a different method?

Thanks;

Sizo Ndlovu

Former Member
0 Kudos

Bill I know you did some Javascripting before in Agentry Rules, are we missing something in the rule above.

Stephen