You need to sign in to do that
Don't have an account?
Renewal Opportunity
Hi Does anyone know how to edit the following code to add 365 days to the close date of the new opp.
try{ {!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} // ** EDIT THIS QUERY TO LIST THE FIELDS YOU WANT TO COPY ** var result = sforce.connection.query("Select o.Type, o.StageName, o.Description, o.Amount, o.AccountId From Opportunity o WHERE o.Id = '{!Opportunity.Id}'"); var newOpp = result.getArray("records"); // Reset the Opp Id and reset fields to default values newOpp[0].Id = ''; newOpp[0].Name = "Renewal - {!Opportunity.Name}"; // ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES ** newOpp[0].StageName = "Prospecting"; newOpp[0].CloseDate = new Date(2099, 0, 1); newOpp[0].Type = "Renewal" var saveResult = sforce.connection.create(newOpp); if (saveResult[0].getBoolean("success")) { newOpp[0].id = saveResult[0].id; alert("Renewal Opportunity Has Been Created."); } else { alert("Failed to create clone: " + saveResult[0]); } // Refresh the page to display the new oppportunity window.location = newOpp[0].id; } catch (err) { alert (err.description ); }
I think it needs to be changed on the "
newOpp[0].CloseDate = new Date(2099, 0, 1);
but i dont know how :S
Thanks if anyone can help as this is important in our company.
Jake
Try this:
// ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES ** newOpp[0].StageName = "Prospecting"; var closeDate = new Date('{!Opportunity.CloseDate}'); closeDate.setYear(closeDate.getFullYear()+1); newOpp[0].CloseDate = closeDate; newOpp[0].Type = "Renewal";