How Can I populate HR case description in HR Task

Anmol12
Tera Contributor

I am having issue populating the description from HR Case to HR Task, I have a rich_description field on both HR case and HR Task and I am setting up some fields on HR Task via HR Template  but it's not able to set the description from HR case in HR Task. Since rich_description field created on case level so {$parent.rich_description} not working as parent will be task table.
I have also tried in workflow script but that is also not working. Can someone help me who came across such issue?

Thanks,
Anmol

2 ACCEPTED SOLUTIONS

Hi @Anmol12,

To populate the 'rich_description' from an HR Case to an HR Task in ServiceNow, you can use a combination of Business Rules, Script Includes, or Workflow Scripts. Since the '{$parent.rich_description}' is not working directly, you may need to manually script the population of the field.

Alternative Approach Using Workflow Script

If you are using a workflow, you can also achieve this with a workflow script:

1. Add a Script Activity to Your Workflow
- Open your HR Case workflow.
- Add a new `Script` activity to the workflow.

2. Configure the Script Activity

 

// Get the current HR Case and its HR Task
var hrTask = current; // Assuming this script runs in the context of an HR Task
var hrCase = new GlideRecord('sn_hr_core_case');

if (hrCase.get(hrTask.parent)) {
// Copy the rich_description from the HR Case to the HR Task
hrTask.rich_description = hrCase.rich_description;
hrTask.update(); // Save the HR Task record
}

 

This script assumes that it is being executed in the context of an HR Task within a workflow. It retrieves the parent HR Case and copies the 'rich_description' to the HR Task.

 

Thank you, please make helpful if you accept the solution.

View solution in original post

@Anmol12  What do you mean by rich_description field is not present on task table ? 

I am just doing dot walk to get parent record field value, in this case parent is holding HR Case record and rich_description exist there so it can fetch the value. 

 

Have you tried to reproduce this on your personal instance ?

If you are doing it on your org instance then try to check any existing BR is not contradicting here ? Also try to lower your BR order to see if it executes or not, add some logs in BR . 

 

Let me know if you have any further question for me.

 

Thanks,

Harsh

View solution in original post

13 REPLIES 13

Yashsvi
Kilo Sage

Hi @Anmol12,

To solve the issue of populating the 'rich_description' from an HR Case to an HR Task using a Business Rule (BR), you can create a Business Rule on the HR Task table that will run before insert and update. This Business Rule will fetch the 'rich_description' from the parent HR Case and set it on the HR Task.

-Business Rule:

-Create a Business Rule on the HR Task Table
-Configure the Business Rule:
- Name: Copy Rich Description from HR Case
- Table: HR Task [sn_hr_core_task]
- When: Before
- Insert: Checked
- Update: Checked

Script:

(function executeRule(current, previous /*null when async*/) {
// Ensure the parent field is not empty
if (current.parent) {
// Get the parent HR Case record
var hrCase = new GlideRecord('sn_hr_core_case');
if (hrCase.get(current.parent)) {
// Copy the rich_description from HR Case to HR Task
current.rich_description = hrCase.rich_description;
}
}
})(current, previous);

This script ensures that every time an HR Task is created or updated, it copies the `rich_description` from the parent HR Case if the parent field is set.

Using these steps, you should be able to successfully copy the `rich_description` from an HR Case to an HR Task using a Business Rule in ServiceNow.

 

Thank you, please make helpful if you accept the solution.

Anmol12
Tera Contributor

I have written a BR but it's not working, not getting any value in logs for the rich description from HR case.

Anmol12
Tera Contributor

Hi Yashvi,
I will try and let you know if it's working through BR, I had to achieve it in a particular HR task only so I had tried the same script in workflow only and it didn't pull the rich _description from HR case. While giving logs it is not holding any value.

Thanks,
Anmol

Hi @Anmol12,

To populate the 'rich_description' from an HR Case to an HR Task in ServiceNow, you can use a combination of Business Rules, Script Includes, or Workflow Scripts. Since the '{$parent.rich_description}' is not working directly, you may need to manually script the population of the field.

Alternative Approach Using Workflow Script

If you are using a workflow, you can also achieve this with a workflow script:

1. Add a Script Activity to Your Workflow
- Open your HR Case workflow.
- Add a new `Script` activity to the workflow.

2. Configure the Script Activity

 

// Get the current HR Case and its HR Task
var hrTask = current; // Assuming this script runs in the context of an HR Task
var hrCase = new GlideRecord('sn_hr_core_case');

if (hrCase.get(hrTask.parent)) {
// Copy the rich_description from the HR Case to the HR Task
hrTask.rich_description = hrCase.rich_description;
hrTask.update(); // Save the HR Task record
}

 

This script assumes that it is being executed in the context of an HR Task within a workflow. It retrieves the parent HR Case and copies the 'rich_description' to the HR Task.

 

Thank you, please make helpful if you accept the solution.