Set Expected Completion Date

🚀 Set Expected Completion Date based on selected priority.

1. Overview

This Interaction is to set the Expected Completion Date based on the selected Priority. It allows adding days, months, years, etc., to the current date or another date field.

👍

Note:

The days parameter in .moment().add() can be adjusted to change the time unit (e.g., years, months, weeks, hours, seconds, etc.).

clev.setValue(  
                "expected-completion-date",  
                clev.moment(ticketSubmitted).add(1, 'days').toISOString()  
            )

2. Examples

Consider the following examples to understand this Interaction:

2.1. Example 1

This example sets the "Expected Completion Date" based on the Scheduled Start date. It adds 3 days to the Scheduled Start date and format the result in the YYYY-MM-DD format.

async function handler(clev) {
    let actions = [];

    const startDate = clev.getValue("scheduled-start");

    actions.push(
        clev.setValue(
            "draft-audit-report-due",
            clev.moment(startDate).add(3, "days").format("YYYY-MM-DD")
        )
    );

    return clev.mergeAll(actions);
}

2.2. Example 2

This example sets the "Expected Completion Date" based on the selected Priority, with varying days added depending on the priority level. For instance, "Urgent" adds 1 day, "Important" adds 5 days, and so forth.

async function handler(clev) {
    let actions = [];

    let priority = clev.getValue("priority");
    const ticketSubmitted = new Date(clev.getValue("issued-at"));

    if (priority == "115504") {
        //Urgent
        actions.push(
            clev.setValue(
                "expected-completion-date",
                clev.moment(ticketSubmitted).add(1, 'days').toISOString()
            )
        );
    } else if (priority == "115505") {
        //Important
        actions.push(
            clev.setValue(
                "expected-completion-date",
                clev.moment(ticketSubmitted).add(5, 'days').toISOString()
            )
        );
    } else if (priority == "115506") {
        //Normal
        actions.push(
            clev.setValue(
                "expected-completion-date",
                clev.moment(ticketSubmitted).add(7, 'days').toISOString()
            )
        );
    } else if (priority == "115507") {
        //Low
        actions.push(
            clev.setValue(
                "expected-completion-date",
                clev.moment(ticketSubmitted).add(10, 'days').toISOString()
            )
        );
    } else {
        //empty
        actions.push(
            clev.setValue(
                "expected-completion-date",
                clev.moment(ticketSubmitted).add(7, 'days').toISOString()
            )
        );
    }
    return clev.mergeAll(actions);
}

2.3. Example 3

In this example, the "Expected Completion Date" is set by adding 3 days to the date the ticket was issued (issued-at).

async function handler(clev) {
    let actions = [];

    const openDate = new Date(clev.getValue("issued-at"));
    openDate.setDate(openDate.getDate() + 3);

    actions.push(clev.setValue("expected-completion-date", clev.moment(openDate).toISOString()));

    return clev.mergeAll(actions);
}

2.4. Example 4

This example sets the date field to be one month ahead of the current date. It uses the moment() function to add 1 month to the current date and format the result in the YYYY-MM-DD format.

async function handler(clev) {
    return clev.setValue(
        "date",
        clev.moment().add(1, "months").format("YYYY-MM-DD")
    );
}

📌 Need Help?

If you require assistance or encounter any issues, please don't hesitate to contact us for further support.