Can we populate 1st task number in the work notes of 2nd task in workflow.

spandana kalla
Tera Contributor

Hi Community,

Can we populate the 1st catalog task number to the work notes of the 2ns catalog task in workflow. Can anyone please help me.

 

Thanks,

Spandana.

4 REPLIES 4

Riya Verma
Kilo Sage
Kilo Sage

HI There,

Here's the high-level solution:

  1. Create a Business Rule on the 2nd catalog task table (e.g., sc_task) to trigger the action when a new record is inserted.

  2. In the Business Rule, use a script to retrieve the 1st catalog task number associated with the same parent request (request number) as the current 2nd catalog task.

  3. Once you have the 1st catalog task number, update the work notes field of the current 2nd catalog task with this information.

Here's a code snippet to illustrate the solution:

// Business Rule on the 2nd catalog task table (sc_task)
// Set the 'When' field to "Before" and 'Insert' for the 'Insert' operation.

(function executeRule(current /* GlideRecord */) {
    // Check if the current 2nd catalog task has a parent request (request number)
    if (current.request) {
        // Query the 1st catalog task associated with the same parent request
        var firstCatalogTask = new GlideRecord('sc_task');
        firstCatalogTask.addQuery('request', current.request);
        firstCatalogTask.orderBy('sys_created_on'); // Assuming you want the first task created.
        firstCatalogTask.setLimit(1);
        firstCatalogTask.query();

        // If the 1st catalog task is found, update the work notes of the current 2nd catalog task.
        if (firstCatalogTask.next()) {
            current.work_notes = '1st catalog task number: ' + firstCatalogTask.number;
        }
    }
})(current);
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

@Riya Verma 

It's not working. Can you please help.

 

Thanks,

Spandana.

@spandana kalla , where its getting stuck?

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

@Riya Verma the script itself is not working . I created the business rule and then for testing purpose i submitted the request to the form and then checked it in the catalog tasks, it's not populating.

 

Thanks,

Spandana.