1

I am a fresher in oracle apex, need some inputs.

There is a form to enter header information. In that there is a date field :P100_ENTERED_DATE, if this field value is less than current date then we need to enable another field :P_100_REASON and make it mandatory.

Any suggestions would be of great help.

I tried to do with JS expression to put in the client side condition like below but did not work.

WHEN: Event: Change Type: Item Item(s): :P100_ENTERED_DATE

Client-side Condition: Javascript Expression.

JS Expression:

var ld_cust_date = apex.item("P102_CUST_REQUEST_DATE").getValue();
var current_date = new Date();

if ((current_date - ld_cust_date) > 2){
    return true
  }  
else {
    return false
}

True Condition: Enable the field (I also want to make it mandatory, not sure how to do this) False Conditoin: Disable the field.

1 Answer 1

1

This might be one option:

  • there are 4 items on a page:
    • P100_SYSDATE
      • hidden
      • source is function body: return to_char(sysdate, 'dd.mm.yyyy');
    • P100_ENTERED_DATE
      • date picker
      • format mask: dd.mm.yyyy
    • P100_DATE_DIFF
      • hidden
      • it will contain difference between sysdate and entered date
    • P100_REASON
      • text item

Create dynamic action on P100_ENTERED_DATE which fires on Change event and contains 4 true actions:

  • hide reason on initialization
    • action: hide
    • affected element: P100_REASON
    • fire on initialization
    • client side condition: item is null, P100_REASON
  • set date diff
    • action: set value
    • PL/SQL expression: to_date(:P100_SYSDATE, 'dd.mm.yyyy') - to_date(:P100_ENTERED_DATE, 'dd.mm.yyyy')
    • items to submit: P100_SYSDATE, P100_ENTERED_DATE
  • show reason:
    • action: show
    • affected element: P100_REASON
    • client side condition: item > value; P100_DATE_DIFF; 0
  • hide reason
    • action: hide
    • affected element: P100_REASON
    • client side condition: item <= value; P100_DATE_DIFF; 0

Create validation on P100_REASON:

  • type is function body, returning error text

    if :P100_DATE_DIFF > 0 and :P100_REASON is null then
       return ('Reason is required');
    end if;
    

That's it. Here are a few testing screenshots (today = SYSDATE = 04.07.2023, 4th of July 2023)

  • A: entered date is 02.07.2023 so "reason" has to be displayed and has to contain some value. Submit button raised an error as "reason" is empty
  • B: once I entered reason, page was successfully submitted
  • C: date (06.07.2023) is after today so "reason" shouldn't be displayed and isn't required. Submit ... well, submits the page

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for spending time on this.. I will give a try and let you know if it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.