Subtract 90 days from u_end_date (date) and set this value in new field (u_expiration_date)

Enkhdalai
Tera Expert

Hi, I have been trying to add expiration date in table and this expiration date field (u_expiration_date) is 90 days from end date field (u_end_date). 

First I need to write fix script and later i need to write new business rule when record updates end date, expiration date updated accordingly. 

I tried to write fix script first but I'm really stuck. 

 

var grexp=new GlideRecord("u_ssl_certificate");
grexp.addEncodedQuery("u_end_dateISNOTEMPTY");
grexp.query();
while(grexp.next()){
var gdt = new GlideDateTime('current.u_end_date');
var expdate = new GlideDateTime('current.u_expiration_date_90_days');
gdt.addDays(-90);
expdate = gdt;

grexp.update();

1 ACCEPTED SOLUTION

@Enkhdalai 

On which table you have written the business rule? and which type of business rule you are asking? (insert/update (before/after))

Let me know the above details.. if possible put screenshots of the same.

View solution in original post

4 REPLIES 4

Raghu Ram Y
Kilo Sage

Hi, 

Try the below script, Working..Tested.

var grexp=new GlideRecord("u_ssl_certificate");
grexp.addEncodedQuery("u_end_dateISNOTEMPTY");
grexp.query();
while(grexp.next()){
var gdt = current.u_end_date.getGlideObject();  //make sure to use correct field names
gdt.addDays(-90);
cuurent.u_expiration_date_90_days = gdt.getDate();
grexp.update();

If my suggestion helps you, then don't forgot to mark it as CORRECT and HELPFUL.

hi, below are error message. 

 

Evaluator: org.mozilla.javascript.EcmaError: Cannot read property "u_end_date" from null
   Caused by error in script at line 5

find_real_file.pngfind_real_file.png

@Enkhdalai 

On which table you have written the business rule? and which type of business rule you are asking? (insert/update (before/after))

Let me know the above details.. if possible put screenshots of the same.