ui action

Vedavalli
Tera Expert

I have a a button which creating a record in task table when i click on publish button.
but the requirement is if today is start date and end date is 16 so when I click on publish then it should create 6 tasks in task table how it is possible?

5 REPLIES 5

Maddysunil
Kilo Sage

@Vedavalli 

I think you can update your code like below:

 

    // Calculate the number of tasks to create (assuming 6 days difference)
    var startDate = current.getValue('start_date'); // Assuming 'start_date' is the field name
    var endDate = current.getValue('end_date'); // Assuming 'end_date' is the field name
    var numberOfDays = gs.dateDiff(startDate, endDate, true); // Calculate the difference in days
    var numberOfTasks = numberOfDays + 1; // Add 1 since the end date should also have a task

    // Create tasks
    for (var i = 0; i < numberOfTasks; i++) {
        var newTask = new GlideRecord('task');
        newTask.initialize(); // Initialize a new task record
        newTask.setValue('parent', g_form.getUniqueValue()); // Link tasks to the original record
        // Set other task fields as needed
        newTask.insert(); // Insert the task record
    }

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

In UI action should I modify

Yes as you need it on click of button

I am using scoped application datediff function is not allowed it is showing this error