- 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 12:19 AM
I think it's because your gdt IS the datefieldA object.
try by using var gdt = new GlideDateTime(current.dateFieldA) (I'm saying it by memory) so you'll have a "completely new gdt GlideDateTime object" to manipulate
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2015 12:57 AM
Hi David,
Thanks for the suggestion, I had already tried that as well with no positive results...
Had also tried:
var gdt = new GlideDateTime(current.dateFieldA)
gdt.addDays(-1 * current.IntegerField);
current.dateFieldB = gdt.getDate();
Didn't work either... any other suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2015 01:07 AM
if you are copy, paste the above code then you are missing semi colon (;) in first instruction .Also date field accept time also and in last instruction ... assign gdt
var gdt = new GlideDateTime(current.dateFieldA) ;
gdt.addDays(-1 * current.IntegerField);
current.dateFieldB = gdt ;
// if its not working ... try to replace last instruction with current.dateFieldB = gdt.toString()
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2015 01:17 AM
Hi Gurpreet,
The first was not copy paste... double checked just in case
Tried amending the last instruction and still nothing shows up on the empty date field.
Checked for typos as well...
Tried with before and after update / insert BRs... still same result.
Other suggestions?