function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KC0798KC0798 

Retrieving date field and adding days to that field

I'm looking to update a date field that I've queried and add days to that field. Anyone can tell me how I can convert the field? The value is just appending as string.
 
I have the following but can't figure out how to convert:
 
var opportunities = sforce.connection.query(
                                                                   // where Progress_Claim_Interval__c is a number value
"SELECT Id, AccountId, Claim_Date__c, Progress_Claim_Interval__c " +
"FROM Opportunity WHERE "+
"Claim_Date__c <> NULL and "+
"Claim_Date__c < today"
);
 
  var rec = opportunities.getArray("records");
  for (var i = 0;i<rec.length;i++) {
    alert("Old Claim Date:"+rec[i].Claim_Date__c);
    rec[i].Claim_Date__c = rec[i].Claim_Date__c + rec[i].Progress_Claim_Interval__c; //How can I do this?
    alert("New Claim Date:"+rec[i].Claim_Date__c);
  }
 
Many Thanks!
werewolfwerewolf
That field will be in Javascript Date format, so use its methods to add days, like this article describes.
WhyserWhyser


KC0798 wrote:
I'm looking to update a date field that I've queried and add days to that field. Anyone can tell me how I can convert the field? The value is just appending as string.
 
I have the following but can't figure out how to convert:
 
var opportunities = sforce.connection.query(
                                                                   // where Progress_Claim_Interval__c is a number value
"SELECT Id, AccountId, Claim_Date__c, Progress_Claim_Interval__c " +
"FROM Opportunity WHERE "+
"Claim_Date__c <> NULL and "+
"Claim_Date__c < today"
);
 
  var rec = opportunities.getArray("records");
  for (var i = 0;i
    alert("Old Claim Date:"+rec[i].Claim_Date__c);
    rec[i].Claim_Date__c = rec[i].Claim_Date__c + rec[i].Progress_Claim_Interval__c; //How can I do this?
    alert("New Claim Date:"+rec[i].Claim_Date__c);
  }
 
Many Thanks!


What is the Progress_Claim_Interval__c?
 
Is it in days, months, years???
 
The line of code in question (// how can I do this) should read something like (assuming Progress_Claim_Interval__c is in days):
 
// Create a temp variable that will store the updated claim date value.
// Use getDate() to retrieve the value as a date object, otherwise it will return as a string
var Claim_Date__c_Update;
Claim_Date__c_Update = rec[i].getDate("Claim_Date__c");
 
// use the SetDate() function in javascript that will take the current claim_date value and add the Process Claim Interval value.
// Remember again to retrieve the Progress Claim Interval value with the getInt() function, otherwise it will return as a string value.
Claim_Date__c_Update = Claim_Date__c_Update.setDate( Claim_Date__c_Update.getDate() + rec[i].getInt("Progress_Claim_Interval__c") );
 
// Update the claim date value.
rec[i].Claim_Date__c = Claim_Date__c_Update;
KC0798KC0798
Great Stuff! That did the trick! Thanks!