Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Auto Update the current date on Decom Date field when the status of a DB is being updated to Decom

Bijay Kumar Sha
Giga Guru

Hi,

I've a requirement that Decom Date on Database CI should automatically update in list view once the CI status change to Disposed. 

I've a below Script Include and a OnChange Client script which is working fine for form label which means if I update the Install Status of a DB CI to Disposed, then automatically the current date & time is reflecting on Decommission Date variable (It'll be mandatory & visible on the form on form level if the Install Status is Disposed).

BijayKumarSha_0-1727184561188.png

BijayKumarSha_1-1727184592729.png

 

However, when I'm updating the Install Status of the DB CIs through list view, then the Status is being updated to Disposed but the Decommission Date is showing mandatory & blank. It should take the current date & time.

1 ACCEPTED SOLUTION

amaradiswamy
Kilo Sage

Hi @Bijay Kumar Sha 

 

Client scripts will work only on the forms, so we need to create a server side script i.e., business rule in this case to update the field

 

Create a before insert/update business rule with trigger conditions as

 

Install status changes to Disposed

Decommission date is empty

 

Check advanced and write the script as

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

	current.decommission_date = new GlideDateTime().getDisplayValueInternal();//CHANGE THE FIELD NAME AS PER YOUR INSTANCE

})(current, previous);

View solution in original post

1 REPLY 1

amaradiswamy
Kilo Sage

Hi @Bijay Kumar Sha 

 

Client scripts will work only on the forms, so we need to create a server side script i.e., business rule in this case to update the field

 

Create a before insert/update business rule with trigger conditions as

 

Install status changes to Disposed

Decommission date is empty

 

Check advanced and write the script as

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

	current.decommission_date = new GlideDateTime().getDisplayValueInternal();//CHANGE THE FIELD NAME AS PER YOUR INSTANCE

})(current, previous);