12 Replies Latest reply on Oct 30, 2018 12:19 PM by Srini-S

    Dynamic action

    Srini-S

      I have a date and duration (hrs) field on a page and would like to add these two dynamically to default and update (if user updates any of the first two fields)  a  third field called end date automatically.  Can someone guide me how to do it? When I use default, it works, but when I update the duration, the end date field does not get updated.

       

      Thanks  in advance

      Regards

      Srini

        • 1. Re: Dynamic action
          Pavel_p

          Hi Srini,

          it looks like you want to bind your DA to two items which is pretty simple. Let's suppose that you want to calculate (server-side) the end_date item like date + duration and we have 3 items - P2_DATE (datepicker), P2_DURATION and P2_END_DATE.  So create a DA of Type Set Value like this:

          When section:

          Event: Change

          Selection Type: Item(s) -- note that you can specify more items at once

          Item(s): P2_DATE,P2_DURATION

          and then a Set Value True Action

          Set Type: PL/SQL Expression

          Expression: to_date(:p2_date, :app_nls_date_format) + :p2_duration -- :app_nls_date_format is a global variable that holds date format mask

          Items to Submit: P2_DATE,P2_DURATION (as they are both used in the calculation)

          Affected Elements:

          Selection Type: Item(s)

          Item(s): P2_END_DATE

          Regards,

          Pavel

          • 2. Re: Dynamic action
            Srini-S

            Pavel

            Thanks for your response and suggestion. What is server side? Though the data is queried in these two source fields , it may be updated by user and then the data is not sent back to server, rather used for calling a pl/sql code through processing and this new arrived date passed.

            Regards

            Srini

            • 3. Re: Dynamic action
              Srini-S

              It worked, thank you. I still am looking for what is server side. Also, any updates to date or duration does not seem to be refreshed. We are making the end date as read only as we don't want users to update it.

              • 4. Re: Dynamic action
                Pavel_p

                I think it needs to explain some basics and I'm sorry if these are already obvious. You have a client-side (browser with its technologies like JavaScript, HTML, CSS...) and server-side (Oracle DB with its SQL and PL/SQL). The server has no idea what is happenind client-side (and vice versa), e.g. if the value of any item changes in the browser , the server has absolutely no idea about that change  until you submit (post) its client-side value to the server (that's why we specified those two items the calculation uses as Item(s) to Submit). Then the actual calculation is performed inside the database in PL/SQL anonymous block (on the server) and the calculated result is returned back to the browser.

                It would be also possible to perform the calculation client-side using JavaScript, however you would have to get the date format setting from the date picker and then perform some date math in Javascript, however the server-side calculation seems to be easier and more reliable, the drawback is one server round-trip as you need to send data to the server and get the calculated result back.

                • 5. Re: Dynamic action
                  Pavel_p

                  Also, any updates to date or duration does not seem to be refreshed

                  Please, could you describe in more detail what updates you mean and where they come from? The described method works no matter if the end date item is editable or not.

                  • 6. Re: Dynamic action
                    Srini-S

                    Pavel

                    Thanks again.

                    We have start date, duration and end date fields in first region. These are defaulted using a query and that fetches values from database to start with(source-pl/sql query). User will then need to update start date or duration or both in which case the end date-time definitely need to be refreshed. Finally when the three values are ready, these are sent to call an API through a package. Whatever is changed by user (date and duration) are not reflected  on the end date. I have used another dynamic action on these two fields to refresh the value when 'changed' That does not seem to work as well.

                     

                    I am very new to APEX, please pardon my ignorance and thanks for your patience.

                     

                    Regards

                    Srini

                    • 7. Re: Dynamic action
                      Srini-S

                      The change in start date or duration is not refreshing the end date-time, though the initial value is correct (start+duration). Some trigger is not defined or working as expected I guess. The definition of dynamic action on start date and duration already mention that 'Refresh' to be done on end date. This does not seem to be happening.

                      • 8. Re: Dynamic action
                        Pavel_p

                        No need to be sorry, it takes time and effort to get familiar with any new tool and some confusion and struggling is just natural.

                        But to your problem... You obviously missed the part about submitting items as there are no items specified as Item(s) to submit in your True action (PL/SQL Expression). If you do not specify these, the server has no idea about the changed data on the client (in the browser), so the action is actually triggered but it always calculates with same values (those at page load), so the result is of course always the same as well. Other than that your DA seems OK however I cannot see all the items on the provided screenshot. As an aside, keep the common naming convention for page items PX_ITEM_NAME where X is your page number as is suggested by the page designer. APEX item cannot be refreshed and also there is no need to refresh as the Set Value DA does everything.

                        1 person found this helpful
                        • 9. Re: Dynamic action
                          Srini-S

                          Thank you again. The issue was that I had included an additional item in 'To submit' and when I removed that item( start time ,which I am not using temporarily but plan to use it) , it started working as expected and it refreshes the data now.

                          • 10. Re: Dynamic action
                            Pavel_p

                            Maybe you meanwhile made some other changes, my answer was related to what I saw on the attached screenshot and there was the field blank.setval_da.jpg

                            • 11. Re: Dynamic action
                              Srini-S

                              My Bad. I took screenshots sometime back and posted here too. I had made quite a few changes after that, I should have posted the most recent ones.

                              • 12. Re: Dynamic action
                                Srini-S

                                Pavel

                                By the way, thanks for the suggestion on the naming too. Once I have the functionality working, I will focus on the part as well. As of now, I still have one issue, that I posted as another thread as it has got to do with Date format handling.

                                 

                                Regards

                                Srini