Task to be created when changes are made in user profile

divyal09
Tera Contributor

We need a TASK ticket created to Account Management team when changes are made to below fields in user’s profile. 

  • Division
  • Department
  • Title

Ticket should contain both the old and new details.

Thanks in advance.

1 ACCEPTED SOLUTION

Ratnakar7
Mega Sage
Mega Sage

Hi @divyal09 ,

 

You can write Business Rule on sys_user table, below are the steps:

  1. Create a Business Rule: Create a Business Rule on the sys_user table. This Business Rule will trigger whenever a record is updated, specifically when changes are made to the fields you mentioned (Division, Department, Title).

  2. Configure the Condition: In the Business Rule, set up a condition that checks if any of the specified fields have changed. You can use the previous and current objects to compare the old and new values.

  3. Create a Task: If the condition is met (i.e., changes to the specified fields are detected), create a new task record. You can use a script to fill in the details of the task, including the old and new values of the fields.

Here's an example of what the Business Rule script might look like:

(function executeRule(current, previous /*null when async*/) {
    // Check if Division, Department, or Title fields have changed
    if (
        current.division != previous.division ||
        current.department != previous.department ||
        current.title != previous.title
    ) {
        // Create a new task record
        var task = new GlideRecord('task');
        task.initialize(); // Initialize a new task record
        
        // Set task details
        task.short_description = 'User Profile Update';
        task.description = 'Changes detected in user profile:\n';
        task.description += 'Old Division: ' + previous.division + '\n';
        task.description += 'New Division: ' + current.division + '\n';
        task.description += 'Old Department: ' + previous.department + '\n';
        task.description += 'New Department: ' + current.department + '\n';
        task.description += 'Old Title: ' + previous.title + '\n';
        task.description += 'New Title: ' + current.title + '\n';
        
        // Set the assignment group and other task details as needed
        task.assignment_group.setDisplayValue('Account Management');
        
        // Insert the task record
        task.insert();
    }
})(current, previous);

 

Thanks,

Ratnakar

View solution in original post

2 REPLIES 2

Ratnakar7
Mega Sage
Mega Sage

Hi @divyal09 ,

 

You can write Business Rule on sys_user table, below are the steps:

  1. Create a Business Rule: Create a Business Rule on the sys_user table. This Business Rule will trigger whenever a record is updated, specifically when changes are made to the fields you mentioned (Division, Department, Title).

  2. Configure the Condition: In the Business Rule, set up a condition that checks if any of the specified fields have changed. You can use the previous and current objects to compare the old and new values.

  3. Create a Task: If the condition is met (i.e., changes to the specified fields are detected), create a new task record. You can use a script to fill in the details of the task, including the old and new values of the fields.

Here's an example of what the Business Rule script might look like:

(function executeRule(current, previous /*null when async*/) {
    // Check if Division, Department, or Title fields have changed
    if (
        current.division != previous.division ||
        current.department != previous.department ||
        current.title != previous.title
    ) {
        // Create a new task record
        var task = new GlideRecord('task');
        task.initialize(); // Initialize a new task record
        
        // Set task details
        task.short_description = 'User Profile Update';
        task.description = 'Changes detected in user profile:\n';
        task.description += 'Old Division: ' + previous.division + '\n';
        task.description += 'New Division: ' + current.division + '\n';
        task.description += 'Old Department: ' + previous.department + '\n';
        task.description += 'New Department: ' + current.department + '\n';
        task.description += 'Old Title: ' + previous.title + '\n';
        task.description += 'New Title: ' + current.title + '\n';
        
        // Set the assignment group and other task details as needed
        task.assignment_group.setDisplayValue('Account Management');
        
        // Insert the task record
        task.insert();
    }
})(current, previous);

 

Thanks,

Ratnakar

Thanks!!! It worked.