+ Start a Discussion
kstites1kstites1 

Contract S-control

<html> <head> <script src="/soap/ajax/11.1/connection.js" type="text/javascript"></script> <title>Executed Contract Received</title> <script> function setupPage() { var conn = sforce.connection; var today = new Date(); contract.AccountId = "{!Opportunity.AccountId}"); contract.RecordTypeId = "012300000000ojo"; contract.Initial_Term_months__c = "36"; contract.Content_Rights_Alteration__c = "Standard"; contract.Content_Rights_Assoc_WS__c = "Standard"; contract.Content_Rights_Term__c = "Standard"; contract.Content_Rights_Use_other_than_Assoc_WS__c = "Standard"; contract.Contract_Expiration_Date__c = "Measured from Launch Date"; contract.Data_Use_Restrictions__c = "Standard"; contract.Pricing_Parity__c = "Standard"; contract.Content_Parity__c = "Standard"; contract.Selection_Parity__c = "Standard"; contract.Tax_Collection_Offered__c = "None"; contract.Insurance_Terms_Standard_as_per_Form__c = "Standard"; contract.A_Z_Guarantee__c = "Standard"; contract.Name = "MAPA"; contract.Agreement_Type__c = "JP M@ 1.0 Gold"; contract.Assigned_Attorney__c = "Kayoko Kurose"; contract.Executed_Agreement_Received__c = "Yes"; contract.Seller_Early_Termination_Rights__c = "No"; contract.Agreement_Party_Country__c = "Japan"; contract.Amazon_Sites__c = "Amazon.co.jp"; contract.Content_Rights_Territory_Channel__c = "Japan"; contract.Effective_Date__c = "Today"; var saveContract= conn.create([contract]); var contractid=saveContract[0].id; var shortid=contractid.substring(0, 15); var result = sforce.connection.create([contract]); var contractid = result[0].id; var contracttype="M@ JP Agreement"; var oppid="{!Opportunity.Id}"; var contractlink = new sforce.SObject("Contract2Opp__c"); contractlink.Contract__c = contractid; contractlink.Opportunity__c = oppid; contractlink.Contract_Type__c = contracttype; var result = sforce.connection.create([contractlink]); var myObj = new sforce.SObject("Opportunity"); myObj.id = oppid; myObj.Contract_ID__c = shortid; myObj.Locale__c = "JP"; var saveResults = conn.update([myObj]); //render the generated html string var retUrl = "https://na1.salesforce.com/" + contractid; window.parent.parent.location.href = retUrl; } </script> </head> <body leftmargin="20" bgcolor=#000099 onload="setupPage()"> <H2><BR><BR><BR><font color = #FFFFFF>Creating New Contract...</font></H2> <div id="output"> </div> </body> </html>

 

This is broken can anyone help me?
DevAngelDevAngel
You wanna give us a clue as to what it does and how it's broken?
kstites1kstites1
It is a link off an opportunity that creates a contract and attaches the contract record to the opportunity.  When you click it now it just goes to a blank white screen.
DevAngelDevAngel

Ok, well I don't know if this will fix the problem, but you could give it a try.

 

The code, about half way down looks like this:

 

 

var saveContract= conn.create([contract]);
var contractid=saveContract[0].id;
var shortid=contractid.substring(0, 15);
var result = sforce.connection.create([contract]);

This is wierd code because it is attempting to create the the contract twice, each with a different object (conn the first time and sforce.connection the second).  Conn is declared as sforce.connection to that redundency should be removed.

 

Then a few lines below this the newly created contract id is being used, but rather than using the one in the variable shortid, the id is coming from result[0].id.

 

Also, contractid is declared twice. (WTH?)

 

 

Here is a cleaned version:

 

<html>
<head>
<script src="/soap/ajax/11.1/connection.js"
type="text/javascript"></script>
<title>Executed Contract Received</title>
<script>
function setupPage()
{

var conn = sforce.connection;

contract.AccountId = "{!Opportunity.AccountId}");
contract.RecordTypeId = "012300000000ojo";
contract.Initial_Term_months__c = "36";
contract.Content_Rights_Alteration__c = "Standard";
contract.Content_Rights_Assoc_WS__c = "Standard";
contract.Content_Rights_Term__c = "Standard";
contract.Content_Rights_Use_other_than_Assoc_WS__c = "Standard";
contract.Contract_Expiration_Date__c = "Measured from Launch Date";
contract.Data_Use_Restrictions__c = "Standard";
contract.Pricing_Parity__c = "Standard";
contract.Content_Parity__c = "Standard";
contract.Selection_Parity__c = "Standard";
contract.Tax_Collection_Offered__c = "None";
contract.Insurance_Terms_Standard_as_per_Form__c = "Standard";
contract.A_Z_Guarantee__c = "Standard";
contract.Name = "MAPA";
contract.Agreement_Type__c = "JP M@ 1.0 Gold";
contract.Assigned_Attorney__c = "Kayoko Kurose";
contract.Executed_Agreement_Received__c = "Yes";
contract.Seller_Early_Termination_Rights__c = "No";
contract.Agreement_Party_Country__c = "Japan";
contract.Amazon_Sites__c = "Amazon.co.jp";
contract.Content_Rights_Territory_Channel__c = "Japan";
contract.Effective_Date__c = "Today";

var saveContract = conn.create([contract]);
var contractid = saveContract[0].id;

var contracttype = "M2 JP Agreement";
var oppid ="{!Opportunity.Id}";
var contractlink = new sforce.SObject("Contract2Opp__c");

 

contractlink.Contract__c = contractid;
contractlink.Opportunity__c = oppid;
contractlink.Contract_Type__c = contracttype;


var saveLink = sforce.connection.create([contractlink]);

var myObj = new sforce.SObject("Opportunity");

 

myObj.id = oppid;
myObj.Contract_ID__c = shortid;
myObj.Locale__c = "JP";

 

var updatedOpptyResults = conn.update([myObj]);




//render the generated html string
var retUrl = "https://na1.salesforce.com/" + contractid;
window.parent.parent.location.href = retUrl;
}

</script>
</head>

<body leftmargin="20" bgcolor=#000099 onload="setupPage()">
<H2><BR><BR><BR><font color = #FFFFFF>Creating New Contract...</font></H2>
<div id="output"> </div>
</body>
</html>

 

 

 

 

 

kstites1kstites1

http://na6.salesforce.com/servlet/servlet.Integration?lid=00b30000000k1z3&eid=0068000000Q7jnh&ic=1

 

this is the url of what is goes to when you click the link.