how to capture time when user deactivated in system record

Deepika61
Tera Contributor

Hi all,

Actually i have created one field on user table, so now i need to capture the time stamp into that field when user deactivated in the record and if the user activated again then the value in that field needs to clear

 

Please help me to achieve this

 

Thanks

Deepika

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi @Deepika61 You can create a Before update BR with condition

Active Changes

script:

if(current.active == true){

var gdt = new GlideDateTime();
current.fieldname= gdt.getDate();
}
else
{
current.fiedlname ='';
}
Regards
Harish

View solution in original post

4 REPLIES 4

Harish KM
Kilo Patron
Kilo Patron

Hi @Deepika61 You can create a Before update BR with condition

Active Changes

script:

if(current.active == true){

var gdt = new GlideDateTime();
current.fieldname= gdt.getDate();
}
else
{
current.fiedlname ='';
}
Regards
Harish

Ankur Bawiskar
Tera Patron
Tera Patron

@Deepika61 

you can use flow designer for this with no script

what did you start with?

If you are using BR then use Before update BR

Condition: Active Changes

Script: Assuming your custom field is of what Date/time type

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

	// Add your code here
	if(current.active == true)
		current.setValue('u_field', new GlideDateTime());
	else
		current.setValue('u_field','');

})(current, previous);

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

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

@Deepika61 

Thank you for marking my response as helpful.

As per new community feature you can mark multiple responses as correct.

If my response helped please mark it correct as well so that it benefits future readers.

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

DpkSharma
Giga Expert

Hi @Deepika61 
Create a New Business rule

Name: Capture Deactivation Timestamp
Table: sys_user
When: Before Update

 

(function executeRule(current, previous) {
  // Check if the user is being deactivated
  if (current.active.changesTo(false)) {
    // Set the timestamp field to the current date and time
    current.field_name = new GlideDateTime();
  } else {
    // Clear the timestamp field if the user is activated again
    current.field_name = null;
  }
})(current, previous);