cancel
Showing results for 
Search instead for 
Did you mean: 

How to provide default date with cap actions

syedimran
Explorer
0 Kudos
191

Hello Experts,

I have custom action in CAP, Any way to default initial date to first day of the month and Final Date to last day of the month?

 
  action updateInvoices
(InitialDate : Date  @Common.Label:'Start Date'  @mandatory,
  FinalDate : Date  @Common.Label:'End Date'  @mandatory)

 

View Entire Topic
catano
Active Participant

Hi @syedimran ,

If it is feasible, you can provide default values on the implementation of the action when you call it with null values.

Remove the mandatory annotation from the parameters:

    action updateInvoices(InitialDate : Date @Common.Label:'Start Date',
                          FinalDate : Date @Common.Label:'End Date' );

Add default date calculation to the implementation of your action:

  srv.on('updateInvoices', async (req) => {
    if (req.data.InitialDate === null) {
      // do the calculation of the first day of the month
    }
    if (req.data.FinalDate === null) {
      // do the calculation of the last day of the month
    }
  });

Call you action:

/updateInvoices(InitialDate=null,FinalDate=null)

OData v4 itself doesn't seem to support default values for action parameters and it would be difficult to declare relative date calculations there.

Regards,
Peter

syedimran
Explorer
0 Kudos
Thanks for answering, I will try this
syedimran
Explorer
0 Kudos
Thanks for answering, I will try this...please let me know if you can answer this