ui action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 05:55 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 06:18 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 07:06 AM
In UI action should I modify
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 07:17 AM
Yes as you need it on click of button
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 07:21 AM
I am using scoped application datediff function is not allowed it is showing this error