You need to sign in to do that
Don't have an account?
cathy369
custom clone button issue... old school... problem with CloseDate
I've created a custom clone button set to execute JavaScript, but for some reason when i try to set a field to value of the original CloseDate, I receive an "undefined" error...as you can see in the code i am trying to set Previous_Order_Date__c to CloseDate, but receive the undefined error.. when i set it to new Date(), it's fine... not sure what to try... thanks much for any help...
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.StageName, o.AccountId, o.Adhesive_Seal__c, o.Priced_Per__c, o.Adjustable_Die__c, o.CloseDate, o.Artwork_Furnished_Via__c, o.Back_PMS_1__c, o.Back_PMS_2__c, o.Back_PMS_3__c, o.Back_PMS_4__c, o.Black_Back__c, o.Black_Front__c, o.Box__c, o.Carton__c, o.Cost_M__c, o.Cut_Sheets_To__c, o.DPE_Inventory__c, o.Envelope_Die_New__c, o.Envelope_Height_inches__c, o.Envelope_Style__c, o.Envelope_Width_inches__c, o.Film__c, o.Flap_Style__c, o.Flexo__c, o.Outside_PMS_1__c, o.Outside_PMS_2__c, o.Form__c, o.Front_PMS_1__c, o.Front_PMS_2__c, o.Front_PMS_3__c, o.Front_PMS_4__c, o.Grain__c, o.Internal_Notes_Materials_Etc__c, o.No_of_Bleeds_Back__c, o.No_of_Bleeds_Front__c, o.No_of_Colors_Back__c, o.No_of_Colors_Front__c, o.No_of_Negatives__c, o.No_of_PMS__c, o.No_of_Shipments__c, o.No_of_Total_Jobs__c, o.Number_Out__c, o.Offset__c, o.Other_Die_Specify__c, o.Other_Envelope_Style_Specify__c, o.Other_Packaging__c, o.Other_Paper_Weight_Specify__c, o.Packaging__c, o.Paper_Stock_Description__c, o.Paper_Type__c, o.Paper_Weight__c, o.Print_Stock_Desc_Free_Form__c, o.Print_Stock_Source__c, o.Standard_Product__c, o.Qty_per_Box__c, o.Qty_per_Carton__c, o.Stock_Source_Product__c, o.Stock_Source_Desc_Free_Form__c, o.Stock_Source__c, o.Run_Factor__c, o.Sample__c, o.Security_Tint__c,o.SheetSize__c, o.Special_Instructions__c, o.Special_Instructions_Prt__c, o.Split_Bill__c, o.Stacking_Instructions__c, o.Tint_PMS__c, o.Custom_Tint_Description__c, o.Window_1_Orientation__c, o.Window_Die__c, o.Window_Die_Sublist__c, o.Window_1_Distance_from_Bottom__c, o.Window_1_Distance_from_Left__c, o.Window_1_Height__c, o.Other_Window_Die_Specify__c, o.Window_1_Width__c, o.Window_2_Orientation__c, o.Window_2_Die__c, o.Window_2_Die_Sublist__c, o.Window_2_Distance_from_Bottom__c, o.Window_2_Distance_from_Left__c, o.Window_2_Height__c, o.Window_2_Other_Die_Specify__c, o.Window_2_Width__c, o.Exact_Repeat__c, Customer_Ship_To__c, Shipping_Street__c, Shipping_City__c, Shipping_State__c, Shipping_Zip_Postal_Code__c, Freight_Zip_Code__c, Delivery_Route__c, Will_Call__c, Ship__c From Opportunity o WHERE o.Id = '{!Opportunity.Id}'"); var newOpp = result.getArray("records"); var recType = sforce.connection.query("select name, id from recordtype where name='Print & Mfg Quote - Rate'"); var records = recType.getArray("records"); var user = sforce.connection.getUserInfo(); // Reset the Opp Id and reset fields to default values newOpp[0].Id = ''; // ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES ** newOpp[0].Name = "{!Opportunity.Name}"; newOpp[0].CloseDate = new Date(); newOpp[0].StageName ="Quote Sent"; newOpp[0].Cloned_From__c = "{!Opportunity.SF_Order_Number__c}"; newOpp[0].Quoted_By__c = sforce.connection.getUserInfo().userId; newOpp[0].Clone_Check__c=true; newOpp[0].Previous_Order__c = "{!Opportunity.SF_Order_Number__c}"; //newOpp[0].Previous_Order_Date__c = "{!Opportunity.CloseDate}"; newOpp[0].Previous_Order_Date__c = new Date(); newOpp[0].Exact_Repeat__c=true; newOpp[0].RecordTypeId='012C0000000MTQG'; var saveResult = sforce.connection.create(newOpp); if (saveResult[0].getBoolean("success")) { newOpp[0].id = saveResult[0].id; alert("*** Quote Created ***"); } else { alert("*** Failed to create Quote: " + saveResult[0]); } // Refresh the page to display the new oppportunity window.location = newOpp[0].id; } catch (err) { alert (err.description ); }
Can you add a debug line and see what is output for "{!Opportunity.CloseDate}"?
I suspect you might need to manipulate/transform that output date value into the proper format to set newOpp[0].Previous_Order_Date__c to the correct date.
Thanks,
Phil
All Answers
Can you add a debug line and see what is output for "{!Opportunity.CloseDate}"?
I suspect you might need to manipulate/transform that output date value into the proper format to set newOpp[0].Previous_Order_Date__c to the correct date.
Thanks,
Phil
thanks for the response... i had no clue how to 'debug' this, but once i did, your are absolutely right... the date needed to be transformed...
I was able to fix this using new Date():
newOpp[0].Previous_Order_Date__c = new Date("{!Opportunity.CloseDate}");
thanks again for your help.
Cathy