Help using Rules for aggregation conditions

I am trying to utilize the application server rules engine to enforce validation on the XML payload. What I am trying to do is use it for a timesheet application, where after a user enters their hours, they submit and it gets some simple validation using the rules engine and gets returned if not valid according to the ruleset. The application supports multiple rows of hours entered, with each row specifying a unique task/activity worked that period. I have it working as I want using XML facts and RL Functions to determine the rules, but I want to take away the RL functions that need to iterate through each row and replace them with aggregate functions in the rule conditions themselves. Here are the rules I want to enforce:
<ul>
<li>An employee must not enter more than x hours of time worked per day, where x is a variable defined in the rules engine. As a constraint the number obviously cannot exceed 24. This rules must span all row entries submitted to sum the amount of hours entered for each day.</li>
<li>An employee must enter at least y hours worked total each week, where y is a variable defined in the rules engine. Typically this will be defined as 40 hours. It must aggregate all hours entered in all rows for the week to determine how many have been submitted.</li>
</ul>
Currently I have 2 RL functions that each return true/false and check the above conditions, but each need to iterate through all rows entered and sum up the hours entered. This is probably satisfactory except my purpose is to show the power of using the rules engine to a client, and if I need to show them I had to develop custom RL code to support this I fear they may shy away from using it.
Here is the general structure of my XML payload:
<Timesheet>
  <EmployeeDetails>
    <FirstName>John</FirstName>
    <LastName>Doe</LastName>
    <EmployeeID>12345</EmployeeID>
  </EmployeeDetails>
  <WeeklyHoursEntries>
    <WeeklyHoursEntryRow>
      <TaskDetails>
        <Activity>TaskActivity1</Activity>
        <Description>Some description here</Description>
        <Category>REG</Category>
      </TaskDetails>
      <HoursEntries>
        <Day1>0</Day1>
         <Day2>8</Day1>
         <Day3>8</Day1>
         <Day4>9</Day1>
         <Day5>5</Day1>
         <Day6>10</Day1>
         <Day7>0</Day1>
       </HourEntries>
     </WeeklyHoursEntryRow>
     <WeeklyHoursEntryRow>
       <TaskDetails>
         <Activity>TaskActivity1</Activity>
         <Description>Some description here</Description>
         <Category>OVT</Category>
       </TaskDetails>
       <HoursEntries>
         <Day1>0</Day1>
         <Day2>2</Day1>
         <Day3>8</Day1>
         <Day4>0/Day1>
         <Day5>0</Day1>
         <Day6>10</Day1>
         <Day7>0</Day1>
       </HourEntries>
     </WeeklyHoursEntryRow>
   </WeeklyHoursEntries>
</Timesheet>

This is an administrators subforum. You might have more luck in some developers subforum here on OTN?

Similar Messages

  • How to use i for if condition in a for i in loop?

    Hi friends,
    I have a question on how to use i for IF condition in a loop, in order to get an efficient programming and results. Here is outlined SQL:
    cursor is
    select c1,c2,c3 from table1; -- 100 rows returned.
    open cursor
    loop
    fetch c1,c2,c3 into v1,v2,v3;
    for i in 1..3 loop
    if 'v'||i between 90 and 100 then
    v_grade := 'Excellent';
    elsif 'v'||i between 80 and 89 then
    elsif 'v'||i between 50 and 59 then
    end if;
    end loop;
    close cursor;
    This way, I don't need to use a lot of if..then for hard code v1,v2,v3,.... actually I have more v..
    But Oracle gave an error of this usage of 'if 'v'||i' or 'v'||to_char(i).
    Thanks for any advice in advance!

    user508774 wrote:
    Thanks for comments and advices. But I didn't get your inputs clearly. Are you saying I don't need to use PL/SQL to achieve this?Correct. Ronel and John showed you the basic approaches. SQL is not a mere I/O language for making read and write calls. It is a very capable, flexible and powerful language. One can solve a problem with a few lines of SQL code, that will take 100's of lines of PL/SQL or Java code.
    So do not underestimate what can be done in SQL.
    v_cmd := 'UPDATE parts_categ_counts SET w1='||v1||', w2='||v2||...||v9||' WHERE seq='||vseq||';
    EXECUTE IMMEDIATE v_cmd;This code is also wrong. Besides the fact that there is no need for dynamic SQL, this approach creates a brand new SQL statement each loop iteration.
    SQL is source code. It needs to be parsed (compiled). The end result is an executable program that is called a cursor. This cursor needs to be stored in server memory (the SQL Shared Pool in the SGA).
    The problem with your code is that it is slow and expensive - it generates lots of unique SQL statements that need CPU for parsing and server memory for storage.
    These add up to a very significant performance overhead. That is the wrong approach. The correct approach is the same one that you would use in any other programming language.
    Let's say you need to use Java to process a bunch of CSV files - exact same CSV layout used by each file. A file needs to be read, processed, and a log file created.
    Will you write a Java program that loops through the files, for each file found, write a Java program for processing that file, compile it, then execute it?
    Or would you write a Java program that takes the name of the file as input, and then process that file and writes the log file?
    The 2nd approach provides a program that can process any of those CSV files - one simply needs to pass the filename as an input parameter.
    Your code and approach use the 1st method. Not the 2nd. And that is why it is wrong.
    To create a SQL program with parameters is done by using bind variables. Instead of
    v_cmd := 'UPDATE parts_categ_counts SET w1='||v1||', w2='||v2||...||v9||' WHERE seq='||vseq||';
    The following SQL source code should be created:
    v_cmd := 'UPDATE parts_categ_counts SET w1=:v1, w2=:v2 ..., w9=:v9 WHERE seq= :vseq';
    The tokens with the colon prefix (such as :v1), are bind variables. Think of these as the parameters to the SQL cursor.
    The server parses this SQL into a cursor. You can now execute the same cursor over and over again, using different bind variables. (just like the 2nd approach above that one would use in Java)
    In PL/SQL, this is made even easier as you can code native SQL code with PL/SQL code and use PL/SQL variables in it. The PL/SQL compiler is clever enough to do the SQL parsing, variable binding, and cursor execution for you. So in PL/SQL, you would use:
    UPDATE parts_categ_counts SET w1=v1, w2=v2 ..., w9=v9 WHERE seq= vseq;
    Where v1 and the others are PL/SQL variables.
    That all said - PL/SQL is only used for data crunching, when the processing of data is too complex for the SQL language to deal with. And this is very seldom the case.
    The main reason for using PL/SQL it to provide processing flow control, conditional processing and error handling, for SQL code. As the SQL language does not have these features.

  • How to assign search help using ovs for select options for ALV in web dynpr

    how to assign search help using ovs for select options for ALV in web dynpro

    Hi,
    refer http://wiki.sdn.sap.com/wiki/display/WDABAP/InputhelpofObjectValueSelectioninWDABAP
    http://www.****************/Tutorials/WebDynproABAP/OVS/page1.htm
    and http://wiki.sdn.sap.com/wiki/display/Snippets/WebDynproAbap-OVSsearch+help
    Thanks,
    Chandra

  • In which condition we need to use Rule for substitution/validation

    Hi Gurus,
       I want to know in which condition I need to use rule instead of directly putting these elements in prerequisite? for example:
    Case1
         Rule:TTYPEARAPO--- BSEG-MATNR <> '' AND BSEG-WERKS <> '' AND BSEG-XBILK <> 'X'
         Prerequisite:TYPEARAPO
    Case2:
         Prerequisite:BSEG-MATNR <> '' AND BSEG-WERKS <> '' AND BSEG-XBILK <> 'X'
    My question is the difference between case1 and case2?  Thanks.

    Wei Gu,
    In the example you have given, there is no difference between these two cases.
    However, imagine that you have to use this same condition in multiple steps / prerequisites / substitutions. In that case, it will be better design to create a 'rule' and then use it at all the places.
    It makes future changes and/or maintenance more manageable.
    HTH,
    Manish Patel
    Sr. SAP Solutions Consultant

  • Need help with Rules for mail accounts

    Today I deleted a rule for a mail account and now I cant receive mail in 4 of 8 accounts. I'm not experienced with Mac's Mail program. Id there something you have to do for multiple accounts to recieve all mail? I can send but not receive.
    Help!
    ~ Tammy

    It's hard to believe that deleting a rule could have a bearing on the ability to receive messages from any account... unless that rule did something that prevented subsequent rules to process the messages that you apparently can't receive now.
    That is, either having deleted the rule has absolutely no bearing on your problem, or the problem is that those messages are now being processed in an unexpected way by some of your other rules.
    What type of accounts are these (POP, IMAP, .Mac)? What does "I cant receive mail in 4 of 8 accounts" mean?

  • Substitution rule for SD Condition type

    We have a pricing procedure ZPOS in which we have SD condition type ZM10 for 7% additional special levy on the basic billing.
    The account key ERS is assigned to the condition type and a GL is assigned to the account key in VKOA settings.
    Based on different invoice types, the special levy amount should hit different GL accounts via a substitution rule without creating multiple condition types.
    Please respond if anyone has a solution to this scenario.

    Hello,
    You can use business transaction event for G/L account changing while posting FI documents.
    But you can use SD exit while transfering SD invoice to FI document.
    Please try this exit below,
    SDVFX004 - User exit G/L line in transfer to accounting - EXIT_SAPLV60B_004
    I hope this exit more useful than substitution.
    Regards,
    Burak

  • Help using workflow for import manager

    hi all,
    assumes import server is used for automation creation/update of records,
    i need to design a workflow to verify existing record  that:
    if a validation pass: update all fields + update mapping key
    if a validation fail : update mapping key only
    can anyone provide good suggestion on how it can be done via workflow?
    MDM API is out of scope...
    thanks,
    Shanti

    Hello Shanti
    Import manager and import server  launch workflow after data loading is finished.
    You cannot manage loading rules from workflow.
    You can create two inbound ports:
    one for keys loading
    another one for keys+fileds loading
    Regards
    Kanstantsin Chernichenka

  • Help Using Spreadsheet for my company Expenses

    I own a medium tier Landscaping Company and want to log all my expenses into a spreadsheet to make life easier for my Accountant at year end. I've started using numbers, and am studying the iwork 09 Apple training series. Can anyone help make this easier for me? Basically, I want to have categories such as: Fuel, Sod, Aggregate, Office Expenses, Advertising, Insurance, Misc, etc and add all the receipts, and have a total at the end before and after tax. What might make it difficult is that it is going to include a lot of entries. ie, 300 gas receipts over a year for example. Any advice? Thank you very much. (Truly Appreciated)

    Hi Sean,
    Welcome to Apple Discussions and the Numbers '09 forum. Glad to see you found it.
    Advantage98 wrote:
    Can you show me the steps to create the summary?
    Here are the steps:
    Open the document containing the Ledger.
    Click on the Tables button, then choose the "Sums" table style from the menu list.
    Move the mouse over the first column's reference tab ("A") and click on the triangle that appears.
    From the menu, choose Convert to Header Column.
    Fill in the column headers in the first row (These can be changed without affecting the table.)
    Fill in the Rw headers in the first column. (These must match the categories in your Ledger table.)
    Add rows if necessary.
    Delete the =SUM(A) formula from the first cell in the bottom row. Retain the formula in the other cells in this row.
    =SUMIF(ExpenseLedger :: $B,$A2,ExpenseLedger :: C)
    Enter the formula provided in Jerry's post (copied above) into cell B2. (Note that "Expense Ledger" should be replaced with the name of your Ledger table if it's not "Expense Ledger")
    Click on and drag the control (small circle at lower right of the selected cell) down to expand the selection and fill in the formula to the last body row of the table.
    Release, then click again on the control and drag right to fill the remaining two columns with the formula.
    Done.
    The best thing that I accomplished today was finding this discussion forum.
    While you're on a roll, I's suggest you download (and spend some time with) the Numbers '09 User Guide and the iWork Formulas and Functions User Guide. Both are available through the Help menu in Numbers.
    Regards,
    Barry
    Sean

  • Use sequence for dynamic conditional grouping

    Hi experts,
    I have a simple(?) task - I want to number (assign) some groups (increasing group number) based on a condition.
    Here an example: create numbered groups based on department number (actual the same grouping)
    create table emp as
    select * from scott.emp;
    CREATE SEQUENCE group_no;
    SELECT group_no.NEXTVAL FROM DUAL;
    SELECT group_no.CURRVAL FROM DUAL;
    /* automatic grouping - NOT WORKING!!!! */
      select ename, deptno, deptno_next, deptno_prev,
       case when (deptno_next > deptno) then group_no.nextval else 1 end grp
        from
          (select ename, deptno,
                  lead(deptno) over (order by deptno) deptno_next,
                  lag(deptno) over (order by deptno) deptno_prev
          from emp
    PROBLEM:
    It seems the sequence is increased, even when the condition for a new number is not met!
    NAME      DEPTNO                 DEPTNO_NEXT            DEPTNO_PREV            GRP                   
    CLARK      10                     10                                            1                     
    KING       10                     10                     10                     1                     
    MILLER     10                     20                     10                     130                   
    JONES      20                     20                     10                     1                     
    FORD       20                     20                     20                     1                     
    ADAMS      20                     20                     20                     1                     
    SMITH      20                     20                     20                     1                     
    SCOTT      20                     30                     20                     135                  
    WARD       30                     30                     20                     1                     
    TURNER     30                     30                     30                     1                     
    ALLEN      30                     30                     30                     1                     
    JAMES      30                     30                     30                     1                     
    BLAKE      30                     30                     30                     1                     
    MARTIN     30                                            30                     1instead of else 1 I will use group_no.currval (same group number, when not changing department). I know, I need to cover the previous number as well, but I made it simple, because the problem here seems to be the sequence...
    Looking forward to your support :-)
    Duik
    Edited by: user10939560 on 08.10.2012 07:42
    Edited by: user10939560 on 08.10.2012 07:44
    Edited by: user10939560 on 08.10.2012 07:45
    Edited by: user10939560 on 08.10.2012 07:48
    Edited by: user10939560 on 08.10.2012 07:49

    Yes, your observation is correct.
    You cant use a sequence this way.
    May be the below gives you a hint to achieve your goal.
    select
    ename
    ,empno
    ,deptno
    ,case
    when lag(deptno, 1, deptno) over (order by deptno) = deptno
    then deptno
    else 30*deptno
    end mark
    from emp
    order by deptno
    ENAME     EMPNO     DEPTNO     MARK
    clark     7782     10     10
    miller     7934     10     10
    KING     7839     10     10
    ford     7902     20     600
    scott     7788     20     20
    jones     7566     20     20
    SMITH     7369     20     20
    adams     7876     20     20
    WARD     7521     30     900
    martin     7654     30     30
    ...Example with consecutive ordering
    select
    ename
    ,empno
    ,deptno
    ,sum(grp) over (order by deptno) grp
    from (
    select
    ename
    ,empno
    ,deptno
    ,case
    when lag(deptno, 1, deptno) over (order by deptno) = deptno
    then 0
    else 1
    end grp
    from emp
    order by deptno
    ENAME     EMPNO     DEPTNO     GRP
    clark     7782     10     0
    miller     7934     10     0
    KING     7839     10     0
    ford     7902     20     1
    scott     7788     20     1
    jones     7566     20     1
    SMITH     7369     20     1
    adams     7876     20     1
    WARD     7521     30     2
    martin     7654     30     2
    ...Edited by: chris227 on 08.10.2012 08:08
    consecutive ordering

  • Help using ipod for photos, music, and video

    Guys, I received an IPOD classic 80gig months ago with a college class that I took. I thought it was really neat at the time as I could watch the videos. However, now I'm so glad that it came free with the class and honestly can't understand how anyone can figure out how to operate it. I have photos, music, and videos that I would love to download to the IPOD and watch but after months of reading and rereading the IPOD features guide, I still have no clue how to do it? I'm a college graduate, made the Dean's list. Smart guy, doesn't seem to help me. The features guide will tell you to go to this folder, etc, BUT when I plug my IPOD in there are only like 4 folders that exist! Where are those folders that they are talking about?? I downloaded some photos on my computer into a folder, dragged and dropped them onto my ipod and when I turn the ipod on it says NO PHOTOS!! Same thing happened with my videos and my music? I have a relative in a nursing home who wants me to show her some family photos. I wanted to IPOD those photos and bring them to her. Can't figure it out! Audiobooks??? No way I'll ever figure out how to do that! Are you guys ALL BRAIN SCIENTISTS OR WHAT???
    Message was edited by: rob25910
    Message was edited by: rob25910

    Thanks Neil, for trying to help me put. I actually figured out how to use the notes. I couldn't believe it worked. I was disappointed to see my notes "cut off" as I guess it has a 4000 character limit, I believe it is. Maybe I'll do a search for itunes software on google and try to figure it out. I don't know if the itunes software is free. You know, not for nothing Neil, but I'm suprised an IPOD classic costs over $250.00 and all they give you is a quick start guide. You have to go to the internet to find a copy of the features guide. That's like buying a new car and not getting an owners manual with it. Odd. Thanks again for trying to help me out.

  • Help using CollatorEntry for Repository Framework Web Services

    Hi All,
    Just wondering what are the pre-requisites needed for my KM repository before I can use the collator functionality in web services such as the findResrouces function from the Repository Framework web service?
    Should my repository be setup with an index or something? I've been reading the Javadocs and trying a few things out using the WSDL navigator but I have no idea what values I should be putting in for CollatorEntry object. What "name" values should I be putting which correspond to properties?
    Could anyone please provide example inputs to put into the WS Navigator say for the method findResources?
    When I test out the findResources method
    when I input rid: /documents/
    CollatorEntries - element1 - name = displayname
    ascending = false
    I keep getting the error:
    Unable to compare: /documents, /documents/.system
    hmmm searching SDN doesn't really seem to come up with much information except Collators aren't being used in client applications so they won't be discussed in detail
    Any help would be appreciated!

    So I have figured out that I need to be putting in the namespace+localname into this collator entry name field but I have been unable to apply an ascending sort based on the accessRid.
    I've found using the findResources operation I am getting back resource objects that are not in a file heiarchal order (ie. nodes further down the file directory are being returned before their parentRids.)
    Is there a way for me to ensure that findResources returns a sorted array that starts from the top of the document tree and each resource object returned is in the same order as what I see in KM content browser?
    Must be a setting or a property that I am missing, when I  do a getOrderMechanism operation I notice it is an unordered type. I can't set server order mechanism as its not supported yet....
    Does anyone have any suggestions?

  • Need Help using ul for horizontal navigation

    Though I normally use tables, I've been reading that it's better to use <ul> and <li> for horizontal navigation bar on my website.
    I'm having problems with spacing, I want each item of the navigation bar to fit in a 166 width box.
    Here's my CSS:
    #ul.navbar {
        list-style-type: none;
      font-weight: bold;  
      background-image: url(../images/166bar.gif);
        margin: 0;
        padding: 0;
        width: 100%;
    #ul.navbar li {
        margin: 0px 20px 10px 20px;
        list-style: none;   
    #ul.navbar a {
        text-decoration: none;
    How do I make sure each item of horizontal navigation bar fits in the center of it's box? Can any recommend a good tutorial or example?

    http://alt-web.com/DEMOS/CSS-Menus.shtml
    Change
    text-align: left
    to
    text-align:center
    I want each item of the navigation bar to fit in a 166 width box.
    In that case, you should use tables, images or vertical list menus.
    http://css.maxdesign.com.au/listamatic/
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb

  • Help using Atv for music...will it transmit back out?

    Imagine this. I want to have an Atv connected to my TV for renting movies but (unfortunately) across the room from my stereo. Will the Atv (possibly with the new software) transmit music stored on its own hard drive back to an airport express (or laptop or actually a squeezebox) connected to my stereo?
    Thanks!

    It certainly won't with the current software and I severely doubt it will with v 2.0, but since it hasn't yet been released I couldn't say with absolute certainty.

  • Limit of for each conditions in rtf templates

    Hi Everyone,
    I have a use case where i need to genereate a report by using values from two data sets. data sales, cost.
    Data set sales have four columns product1, product 2, product 3, product 4
    Cost has cost1,cost 2, cost 3, cost 4.
    I need to display in below format
    product 1| product 2| cost 1|cost 2| product 3| product 4| cost 3| cost 4|
    To get above format i am using four for each condition groupings two for each data set
    <?for-each:/data/sales?><?product1?>|<?product2?><?end for-each?>|<?for-each:/data/cost?><?cost1?>|<?cost2?><?end for-each?>|<?for_each:/data/sales?><?product3?>|<?product 4?><?end for-each?>|<?for-each:/data/cost?><?cost3?>|<?cost4?><?end for-each?>
    If i use first two for each conditions i am able to see values in template but if i use four line is missing in the template.
    I did not understand where lies the problem.
    Please let me know if you need more info.
    Regards
    Sandeep

    If you have product ID or key in the cost data set, then you can follow the method in this post to display data:
    http://blogs.oracle.com/xmlpublisher/2009/09/formatting_concatenated_dataso.html

  • How to use complex function as condition in Oracle Rule Decision Table?

    How to use complex function as condition in Oracle Rule Decision Table?
    We want to compare an incoming date range with the date defined in the rules. This date comparison is based on the input date in the fact & the date as defined for each rule. Can this be done in a decision table?

    I see a couple of problems here.
    First, what you posted below is not a syntactically valid query. It seems to be part of a larger query, specifically, this looks to be only the GROUP BY clause of a query.
    Prabu ammaiappan wrote:
    Hi,
    I Have a group function in the Query. Below is the Query i have used it,
    GROUP BY S.FREIGHTCLASS,
    R.CONTAINERKEY,
    S.SKU,
    S.DESCR ||S.DESCRIPTION2,
    S.PVTYPE,
    RD.LOTTABLE06,
    R.WAREHOUSEREFERENCE,
    RD.TOLOC,
    R.ADDWHO,
    R.TYPE,
    S.CWFLAG,
    S.STDNETWGT,
    S.ORDERUOM,
    R.ADDDATE,
    C.DESCRIPTION,
    (CASE WHEN P.POKEY LIKE '%PUR%' THEN 'NULL' ELSE to_char(P.PODATE,'dd/mm/yyyy') END),
    NVL((CASE WHEN R.ADDWHO='BOOMI' THEN RDD.SUPPLIERNAME END),SS.COMPANY),
    RDD.BRAND,
    S.NAPA,
    RD.RECEIPTKEY,
    R.SUSR4,
    P.POKEY,
    RDD.SUSR1,
    r.STATUS, DECODE(RDD.SUSR2,' ',0,'',0,RDD.SUSR2),
    rd.SUSR3Second, the answer to your primary question, "How do I add a predicate with with a MAX() function to my where clause?" is that you don't. As you discovered, if you attempt to do so, you'll find it doesn't work. If you stop and think about how SQL is processed, it should make sense to you why the SQL is not valid.
    If you want to apply a filter condition such as:
    trunc(max(RD.DATERECEIVED)) BETWEEN TO_DATE('01/08/2011','DD/MM/YYYY') AND TO_DATE('01/08/2011','DD/MM/YYYY')you should do it in a HAVING clause, not a where clause:
    select ....
      from ....
    where ....
    group by ....
    having max(some_date) between this_date and that_date;Hope that helps,
    -Mark

Maybe you are looking for