- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2015 11:39 PM
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:
- var gdt = current.DateFieldA.getGlideObject();
- var minus=current.IntegerField; //substitute your integer column names here
- minus=minus*-1;
- gdt.addDays(minus);
- gs.addInfoMessage(gdt);
- DateFieldB = gdt;
Any help will be highly appreciated!
Cheers,
Luis
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2015 02:22 AM
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
- current.DateFieldB = current.DateFieldA ;
- var gdt = current.DateFieldB.getGlideObject();
- var minus=current.IntegerField; //substitute your integer column names here
- minus=minus*-1;
- gdt.addDays(minus);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2015 01:20 AM
I would like to add a log statement after addDays ... i.e. gs.addInfoMessage(' Date Field B : '+gdt).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2015 01:34 AM
Nothing worked... tried even gs.log also nothing logged. Something must be wrong.
Deleted business rule...
Will start from scratch. Could you try reproducing this on your end?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2015 01:41 AM
var gdt = new GlideDateTime(current.u_datea);
gdt.addDays(-1 * current.u_integerfield);
current.u_dateb = gdt.getDate();
Used the same script on before update business rule.. could not find any issues. I also changed integer field to string... and the date field to date/time. I am getting correct value all the time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2015 02:06 AM
Hi Luis,
Your following code is working for me as well in before business rule:
var gdt = new GlideDateTime(current.dateFieldA)
gdt.addDays(-1 * current.IntegerField);
current.dateFieldB = gdt.getDate();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2015 02:22 AM
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
- current.DateFieldB = current.DateFieldA ;
- var gdt = current.DateFieldB.getGlideObject();
- var minus=current.IntegerField; //substitute your integer column names here
- minus=minus*-1;
- gdt.addDays(minus);