Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

How to Populate date field with the first update made by assigned to user in sc_task table

vivek49
Tera Contributor

I have a custom date/time field "First action date by assigned to". 
when a sc_task record is assigned to a user, then the first update made by this assigned_to user should be populated in the custom date/time field.
I tried it by using BR script 

But it is not working.

Any suggestions how we can achieve this?

Appreciate any suggestions

1 ACCEPTED SOLUTION

YaswanthKurre
Tera Guru

Hi @vivek49 ,

 

Business Rule Configuration

  • Table: sc_task
  • When to run: before update
  • Conditions:
    • assigned_to is not empty
    • u_first_action_date_by_assigned_to is empty
  • Advanced: Checked

Script: 

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

    // Only proceed if the field is empty
    if (!current.u_first_action_date_by_assigned_to) {

        // Check if the user updating the record is the assigned_to user
        if (gs.getUserID() == current.assigned_to.toString()) {

            // Set the current date/time
            current.u_first_action_date_by_assigned_to = new GlideDateTime();
        }
    }

})(current, previous);

 

Please mark this as helpful and correct, if this solves your question.

 

Thanks,

Yaswanth.

 

View solution in original post

3 REPLIES 3

YaswanthKurre
Tera Guru

Hi @vivek49 ,

 

Business Rule Configuration

  • Table: sc_task
  • When to run: before update
  • Conditions:
    • assigned_to is not empty
    • u_first_action_date_by_assigned_to is empty
  • Advanced: Checked

Script: 

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

    // Only proceed if the field is empty
    if (!current.u_first_action_date_by_assigned_to) {

        // Check if the user updating the record is the assigned_to user
        if (gs.getUserID() == current.assigned_to.toString()) {

            // Set the current date/time
            current.u_first_action_date_by_assigned_to = new GlideDateTime();
        }
    }

})(current, previous);

 

Please mark this as helpful and correct, if this solves your question.

 

Thanks,

Yaswanth.

 

J Siva
Kilo Patron

Hi @vivek49 
Try the below BR configuration.

JSiva_0-1750485626102.png

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

	// Add your code here
	current.u_first_action_date_by_assigned_to = new GlideDateTime();

})(current, previous);

 

Regards,
Siva

Ankur Bawiskar
Tera Patron

@vivek49 

unless you share what you tried, we can't help

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader