Multi row variable set, end date of previous record should change basis of current record start date

Gaurav Gupta3
Tera Expert

Hello Everyone

 

Requirement

Working on Multi row variable set on a record producer. When try to create a new contribution record, based on the Start date of the current record it should update the end date of the previous record.   We are using Flow designer, as this entire functionality is working on approval process.  As soon the request is approved, it should update the end date of previous record. 

For example, please check the below screenshots. 

 

GauravGupta3_0-1703226768662.png

 

Present situation:

At present, it is updating only for first record.  However, it should work for every record.

GauravGupta3_1-1703226768666.png

GauravGupta3_2-1703227110230.png

var newDate = new GlideDateTime();
newDate.addDaysUTC(-1);
return newDate.getLocalDate();
 
This script needs to be updated to build that logic and it is not giving the desired result, please help and ask questions to me if not understood.

 

1 ACCEPTED SOLUTION

Kartik Magadum
Kilo Sage

Hello @Gaurav Gupta3 

To achieve your goal of updating the end date of the previous record in a Multi-Row Variable Set on a record producer when creating a new contribution record, you need to identify the previous record and update its end date based on the start date of the current record.

 

var currentStartDate = inputs['current_record.start_date']; // Adjust the field name based on your actual field name
    var previousEndDate = inputs['previous_record.end_date']; // Adjust the field name based on your actual field name

    if (currentStartDate && previousEndDate) {
        var newEndDate = new GlideDateTime(currentStartDate);
        newEndDate.addDaysUTC(-1);

        outputs['updated_end_date'] = newEndDate.getLocalDate();
    } else {
        outputs['updated_end_date'] = null; // Handle the case where either the current start date or previous end date is not available
    }

 

In this script:

  • inputs['current_record.start_date'] represents the start date of the current record.
  • inputs['previous_record.end_date'] represents the end date of the previous record.

Make sure to adjust the field names based on your actual field names.

If the start date of the current record and the end date of the previous record are available, it calculates the new end date by subtracting one day from the current start date. The result is then stored in outputs['updated_end_date'].

 

Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Thanks & Regards,

Kartik Magadum

View solution in original post

5 REPLIES 5

Hi Kartik, 

Where you want me to apply this logic, in Update records section or you want me to create a new Action. 
Also this logic, I didnt understand 

if (currentStartDate && previousEndDate)

This seems to be incomplete without any condition.    Who is marking this helpful, I didnt get it. 

Regards

Gaurav Gupta