You need to sign in to do that
Don't have an account?
Dea73
Javascript custom button not working, anyone with same problem?
I have a cutom button on an object and it's supposed to execute a javascript code.
But today it seems like it doesn't want to work. It just doesn't do anything, it seems like it's not connecting to SF.
Has this happened to anyone else before, and how do you fix it?
Thanks!
But today it seems like it doesn't want to work. It just doesn't do anything, it seems like it's not connecting to SF.
Has this happened to anyone else before, and how do you fix it?
Thanks!
It will be easier to provide help in debugging your issue.
{!REQUIRESCRIPT("/soap/ajax/16.0/connection.js")}
var discoDate = "{!Circuits__c.Disco_Order_Date__c}";
var submitby = "{!Circuits__c.Disco_Submitted_By__c}";
var requestDate = "{!Circuits__c.Dicsonnect_Date_Requested__c}";
var discoType = "{!Circuits__c.Disconnect_Type__c}";
var replaceCircuit = "{!Circuits__c.Replacement_Circuit__c}";
var lnkedDisco = "{!Circuits__c.Disco_Order__c}";
if(lnkedDisco != ''){
alert("A Disco Order is already linked to this circuit.")
}
else if ( discoDate == '' ) {
alert("Disco Date must be entered before initiating a disconnect.")
}
else if ( submitby == '' ) {
alert("Disco Submitted By must be entered before initiating a disconnect.")
}
else if ( requestDate == '' ) {
alert("Disconnect Date Requested must be entered before initiating a disconnect.")
}
else if ( discoType == '' ) {
alert("Disconnect Type must be entered before initiating a disconnect.")
}
else if ( discoType == 'Change' || discoType == 'Renewal' ) {
if ( replaceCircuit == '' ){
alert("Replacement Circuit must be entered before initiating a Change or Renewal disconnect.")
}
} else {
//start creating disco order
alert("Disco Order creation beginning. Please Wait.");
var newOrder = new sforce.SObject("Order__c");
//get assigned to value for provisioning
var provassign = sforce.connection.query("Select Id From User where Alias = 'jlarmore'");
var enableassign = sforce.connection.query("Select Id From User where Alias = 'Enable'");
//see if any off-net circuits are there. If so, add to disco order
var offnetcirc = sforce.connection.query("Select Id from Circuits__c where Supports_Customer_Circuit__c = '{!Circuits__c.Id}'");
var offresults = offnetcirc.getArray("records");
var provResult = provassign.getArray("records");
var enableResult = enableassign.getArray("records");
//query to get information from parent order
var ordInfo = sforce.connection.query("Select Z_Location__c, Z_CPE_Location__c, Opportunity__c, Id, A_Location__c, A_CPE_Location__c From Order__c where Id = '{!Circuits__c.OrderId__c}'");
var ordInfoResult = ordInfo.getArray("records");
newOrder.RecordTypeId = "01230000000UbVO";
newOrder.Account__c = "{!Circuits__c.AccountId__c}";
newOrder.Service_Level__c = "{!Circuits__c.Service_Level__c}";
newOrder.Service_Type__c = "{!Circuits__c.Service_Type__c}";
newOrder.Order_Status__c = "Not Confirmed";
if(discoDate != ''){
newOrder.Order_Date__c = new Date("{!Circuits__c.Disco_Order_Date__c}"); }
newOrder.Order_Type__c = "{!Circuits__c.Disconnect_Type__c}";
newOrder.A_Location__c = ordInfoResult[0].A_Location__c;
newOrder.Z_Location__c = ordInfoResult[0].Z_Location__c;
newOrder.Opportunity__c = ordInfoResult[0].Opportunity__c;
newOrder.Replacement_Circuit_Order__c = ordInfoResult[0].Id;
newOrder.A_CPE_Location__c = ordInfoResult[0].A_CPE_Location__c;
newOrder.Z_CPE_Location__c = ordInfoResult[0].Z_CPE_Location__c;
newOrder.Kill_Site__c = "{!Circuits__c.Kill_Site__c}";
var disconDate = "{!Circuits__c.Disconnect_Date__c}";
if(disconDate != ''){
newOrder.Disconnect_Date__c = new Date("{!Circuits__c.Disconnect_Date__c}");}
//if (offresults[0].Id != null){
if (offresults.length > 0 ){
newOrder.Associated_Off_Net_Circuit__c = offresults[0].Id;
}
newOrder.Provisioning_Assigned_To__c = provResult[0].Id;
//newOrder.Provisioning_Assigned_To__c = enableResult[0].Id;
var discoresult = sforce.connection.create([newOrder]);
if (discoresult[0].getBoolean("success")) {
//now update the circuit
var thisCirc = new sforce.SObject("Circuits__c");
thisCirc.Id = "{!Circuits__c.Id}";
thisCirc.Disco_Order__c = discoresult[0].id;
//update the circuit record
circResult = sforce.connection.update([thisCirc]);
if (circResult[0].getBoolean("success")) {
alert("Disco Order has been created");
location.reload(true);
}
else {
alert("An error has occurred updating the Circuit: " + circResult[0] + ". ");
}
}
else {
alert("Disco Order Fails on " + discoresult[0] + ". ");
}
}
}
catch (error) {
alert ("The following error occurred: " + error );
}
If not already done, I would suggest running the Java Script in all browsers IE, Chrome, Firebox. See if if fails to load in all three.
Secondly, i would add a few console.log statements for debugging.
something like -
console.log("You made it to line 10. But then something went wrong.")
This way you will know which line of code you were able to run your program before it broke.