Worknotes of one task needs to be copied to the next task under the same RITM

Sofiya Perumal
Tera Expert

Hi Team,

 

Under same RITM we have multiple tasks, which means when one task gets closed it will create a new task. So we have some customized fields in the first task. So the same fields will be visible in the next task as well. SO whatever, data is given in the task 1 should get reflected in the task 2 as well. The fields are of data type reference, string , date.

 

Please let me know the feasibility of the same.

 

Regards,

Sofiya

3 REPLIES 3

SN_Learn
Kilo Patron
Kilo Patron

Hi @Sofiya Perumal ,

 

You can try the below business rule to achieve the same:

 

Table: [sc_task]

'Advanced' checkbox will be true

When to run: [after] [update]

 

In the filter define the conditions for your field changes

Example: I have used 'short description changes'

SN_Learn_0-1719121860732.png

 

In the advance section:

(function executeRule(current, previous /*null when async*/ ) {

    var cascadeFieldVal = new GlideRecord('sc_task');
    cascadeFieldVal.addQuery('request_item', current.request_item);
    cascadeFieldVal.query();
    while (cascadeFieldVal.next()) {
        cascadeFieldVal.setValue('short_description', current.short_description); //Update with your field backend names
		cascadeFieldVal.update();
    }

})(current, previous);

 

Output:

 

SN_Learn_1-1719122119064.png

 

 

 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

HrishabhKumar
Kilo Sage

Hi @Sofiya Perumal ,

You can achieve this by using a combination of Script include and Business Rule. I have provided the steps below, try this and see if it works:

1. Create a Script Include

Create a Script Include to handle the copying of field values. This ensures that the logic is reusable and maintainable.

 

 

var TaskHelper = Class.create();
TaskHelper.prototype = {
    initialize: function() {},

    copyCustomFields: function(sourceTask, targetTask) {
        // Add the names of your fields in below array.
        var fieldsToCopy = ['custom_field_1', 'custom_field_2', 'custom_field_3'];
        
        for (var i = 0; i < fieldsToCopy.length; i++) {
            var field = fieldsToCopy[i];
            targetTask.setValue(field, sourceTask.getValue(field));
        }
        
        // Update the target task
        targetTask.update();
    },

    type: 'TaskHelper'
};

 

 

 

2. Create a Business Rule

Create a Business Rule on the sc_task table to trigger when a new task is created and copy the field values from the previous task.

  1. Trigger Conditions: Set the Business Rule to run before insert.
  2. Script: Use the Script Include to copy the values from the previous task.   

 

 

(function executeRule(current, previous /*null when async*/) {

    // Find the previous task in the RITM
    var previousTask = new GlideRecord('sc_task');
    previousTask.addQuery('request_item', current.request_item);
    previousTask.orderByDesc('sys_created_on');
    previousTask.query();
    
    if (previousTask.next()) {
        // Skip copying if it's the first task
        if (previousTask.sys_id != current.sys_id) {
            var taskHelper = new TaskHelper();
            taskHelper.copyCustomFields(previousTask, current);
        }
    }

})(current, previous);
​

 

 

 

 

Thanks,

Hope this helps.

If my response proves helpful please mark it helpful and accept it as solution to close this thread.

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @Sofiya Perumal,

 

can be done via BR or workflow...

 

Step1:

You can attain this via the workflow which is handling the request lets say if the Task1 is closed complete you can place a script activity before the generation of the task2. 

 

Step2: 

In the script activity use g_scratchpad variables to store the varaibles value which needs to be copied to the task2. (gliderecord to get the previous task or you can also use business rule before insert to set values for 2nd task)

 

Step3: in the task2 activity under script field set the value of the field using the previously stored g_scratchpad values.

 

Eg: task.varaible1 = g_scratchpad.value;

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect