The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Adding Integer to Date field to populate another Date field

Luis Nunez
Tera Expert

Hello all,

Need a little help, I am trying to populate date field from another date field which adds an integer.

I have tried business rules, client scripts, calculations on the field itself and nothing seems to work.

Scenario:

I have a set DateFieldA, an IntegerField with values 30, 60, 90 and an empty DateFieldB.

DateFieldB must be the result of DateFieldA minus IntegerField.

The only Business rule that works halfway is the below, however it also changes the date on the DateFieldA (which shouldn't) so at the end, DateFieldA and DateFieldB are the same.

DateFieldA = 30.05.2015

IntegerField = 30 Days (Value is 30)

DateFieldB = should result in 30.04.2015

Halfway working BR:

  1. var gdt = current.DateFieldA.getGlideObject();  
  2. var minus=current.IntegerField; //substitute your integer column names here  
  3. minus=minus*-1;  
  4. gdt.addDays(minus);  
  5. gs.addInfoMessage(gdt);  
  6. DateFieldB = gdt;

Any help will be highly appreciated!

Cheers,

Luis

1 ACCEPTED SOLUTION

Gurpreet07
Mega Sage

Let's do this in another way . You remember that yours partial working business rule was updating both of the dates . Use that kind of logic in following way



  1. current.DateFieldB = current.DateFieldA ;
  2. var gdt = current.DateFieldB.getGlideObject();
  3. var minus=current.IntegerField; //substitute your integer column names here
  4. minus=minus*-1;
  5. gdt.addDays(minus);

View solution in original post

10 REPLIES 10

Worked like a charm...


Thanks!


I will now try to do this whole thread on my test instance and try to figure out why the previous BR wasnt working at all...



Thanks all again!