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
Robert Davis 16Robert Davis 16 

Javascript Date Issue

I have the following code that creates a URL to go to another system. I have a date field that I pull from an ApexController but when it appears in the URL it shows today's date and not the one from the field. I do not get an error (that I know about, quite frankly I am not great with how to use the Developer Tools in Chrome)

Any ideas of the error or how to troubleshoot this?
This is the HELPER:
({
	navigate : function(component) {
        var action = component.get("c.getOpportunity");
		var idOpp = component.get("v.recordId");
        var SCMAid = component.get("v.aid");
        var SCMFormId = component.get("v.formId");
		if(!$A.util.isEmpty(idOpp))
		{
			action.setParams({opportunityId: idOpp});
		
			// Create a callback that is executed after 
			// the server-side action returns
			action.setCallback(this, function(response) {
				var state = response.getState();
				if (state === "SUCCESS") {
					var opp = response.getReturnValue();
                    /* Here you can access like opp.Id, opp.FTEs__c, opp.Account.Industry and form the URL */
                    var fullTimeEmployees = opp.Total_FTEs__c;
                    var industry = opp.Account.Industry;
                    var programStartDate = $A.localizationService.formatDate(Date(opp.ProgramStartDate__c),"MM/DD/YYYY");  
                    var opportunityId = opp.Id;
                    var opportunityName = opp.Name;                    
					var filePath = '/Accounts/'+ opp.Account.Name + '/Opportunities/&ru=%2Fatlas%2Fbpm%2FWorkList.aspx'
                    var partOneURL = 'https://na123.springcm.com/atlas/Forms/UpdateFormDoc.aspx?';
					
                    var partTwoURL = 'aid='+SCMAid;
                    var formUid = SCMFormId;
                    if(SCMAid == '9999') {
                        //Sandbox URL
                        var partOneURL = 'https://uatna123.springcm.com/atlas/Forms/UpdateFormDoc.aspx?';
                    } else {
                        //Production URL
                        var partOneURL = 'https://na123.springcm.com/atlas/Forms/UpdateFormDoc.aspx?';
                    }
					var finalURL = partOneURL + partTwoURL 
                    var finalURL = finalURL + '&FormUid=' + formUid;
                    var finalURL = finalURL + '&SFFTE=' + fullTimeEmployees;
                    var finalURL = finalURL + '&SFIND=' + industry;
                    var finalURL = finalURL + '&SFPSD=' + programStartDate;
                    var finalURL = finalURL + '&SFID=' + opp.Id;
                    var finalURL = finalURL + '&SFNAME=' + opportunityName;
                    var finalURL = finalURL + '&SFWF=ABC';
                    var finalURL = finalURL + '&SFCAFTYPE=CAAF';
                    var finalURL = finalURL + '&SFTYPE=Salesforce.Opportunity';
                    var finalURL = finalURL + '&SFPATH=' + filePath;
                    var urlEvent=$A.get("e.force:navigateToURL");
                    urlEvent.setParams({"url": finalURL});
					urlEvent.fire();
				}
				else if (state === "ERROR") {
					var errors = response.getError();
					if (errors) {
						if (errors[0] && errors[0].message) {
							console.log("Error message: " + 
									 errors[0].message);
						}
					} else {
						console.log("Unknown error");
					}
				}
			});

			// optionally set storable, abortable, background flag here

			// A client-side action could cause multiple events, 
			// which could trigger other events and 
			// other server-side action calls.
			// $A.enqueueAction adds the server-side action to the queue.
			$A.enqueueAction(action);
		}
		else
		{
			console.log('===Record Id is not present====');
		}
	}
})
The variable that I am having the issue with is:
 var programStartDate = $A.localizationService.formatDate(Date(opp.ProgramStartDate__c),"MM/DD/YYYY");  

Not sure why I get today's date and not the one from the controller.

Thanks in advance.

Robert
 
Best Answer chosen by Robert Davis 16
Alain CabonAlain Cabon
Hello,

Just remove Date()

 var programStartDate =$A.localizationService.formatDate(opp.ProgramStartDate__c,"MM/DD/YYYY"); 
 

All Answers

Alain CabonAlain Cabon
Hello,

Just remove Date()

 var programStartDate =$A.localizationService.formatDate(opp.ProgramStartDate__c,"MM/DD/YYYY"); 
 
This was selected as the best answer
Robert Davis 16Robert Davis 16
Alain,

THANK YOU

Robert