You need to sign in to do that
Don't have an account?
RLStallard-GXT
Greetings folks,
I've been banging my head, searching all over SFDC user/developer sites and googled, but still can't find solution. I have read in these forums of others doing this, but they do not post the complete code of how it's done. I am xhtml/css savvy but am a total newbie at JavaScript (except cut 'n' paste) and S-Controls (this is my first attempt).
DESCRIPTION
---------------------------------------------------
This is what I am attempting to do:
[] Create a new record of a Custom Object (Quote/Sales Order) via a custom link on Opportunities that calls an S-Control.
[] The custom object is a related list (child) to opportunities.)
[] When the link is clicked, the S-Control will open the input form page of a new record of the custom object with certain fields prepopulated.
[] These fields are prepopulated with data contained in fields of the related Opportunity and Account.
[] The input page with the prepopulated is to remain open so that the user may complete any remaining fields he/she wishes and then saves the new record.
PURPOSE
---------------------------------------------------
This custom object has fields containing the exact same data as fields in the related Opportunity and Account. Thus the purpose of the S-Control is to improve usability and data integrity by eliminating the need to force users to perform double transcription.
CODE
---------------------------------------------------
Here is the code I wrote with comments on field types and alert results. It doesn't create the new record and returns the saveAlert ID as null.
Code:
I appreciate any guidance you can offer. My users are very annoyed at having to do double entry, causing SFDC adoption to decline significantly in my organization.
Thanks and may you have a great day, everyday!
Robert
rstallard@gxt.com
Please help newbie - creating a new record of custom object. with an s-control
Greetings folks,
I've been banging my head, searching all over SFDC user/developer sites and googled, but still can't find solution. I have read in these forums of others doing this, but they do not post the complete code of how it's done. I am xhtml/css savvy but am a total newbie at JavaScript (except cut 'n' paste) and S-Controls (this is my first attempt).
DESCRIPTION
---------------------------------------------------
This is what I am attempting to do:
[] Create a new record of a Custom Object (Quote/Sales Order) via a custom link on Opportunities that calls an S-Control.
[] The custom object is a related list (child) to opportunities.)
[] When the link is clicked, the S-Control will open the input form page of a new record of the custom object with certain fields prepopulated.
[] These fields are prepopulated with data contained in fields of the related Opportunity and Account.
[] The input page with the prepopulated is to remain open so that the user may complete any remaining fields he/she wishes and then saves the new record.
PURPOSE
---------------------------------------------------
This custom object has fields containing the exact same data as fields in the related Opportunity and Account. Thus the purpose of the S-Control is to improve usability and data integrity by eliminating the need to force users to perform double transcription.
CODE
---------------------------------------------------
Here is the code I wrote with comments on field types and alert results. It doesn't create the new record and returns the saveAlert ID as null.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">---------------------------------------------------
<html>
<head>
<title>Create Quote</title>
<script language="javascript" src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script language="javascript">
<!--
function initPage() {
sforceClient.registerInitCallback(createQuote);
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_60}");
window.setTimeout(";", 1000);
}
function createQuote() {
var quote = new Sforce.Dynabean("Quote_Sales_Order_Data__c");
alert("function initPage() and start of createQuote() running good!") // Alert displays
quote.set("Name", "{!Opportunity_Opportunity_Number}") //Standard text field - Name of custom objext - Required - Reading from Autonumber field
quote.set("Opportunity__c", "{!Opportunity_Name}") //Master-Detail relationship - Parent Opportunity - Required
quote.set("GXT_Business_Unit__c", "{!Opportunity_GXT_Business_Unit}");
quote.set("GXT_Service_Center__c", "{!Opportunity_GXT_Service_Center}");
quote.set("Submission_Date__c", new Date());
quote.set("Survey_Name_Area_Block__c", "{!Opportunity_Survey_Name_Area_Block}");
quote.set("GXT_Project_Manager__c", "{!Opportunity_GXT_Project_Manager}");
quote.set("Geographic_Region__c", "{!Opportunity_Geographic_Region}");
quote.set("Environment__c", "{!Opportunity_Environment}");
quote.set("Country__c", "{!Opportunity_Country}");
quote.set("Dimension__c", "{!Opportunity_Dimension}");
quote.set("Expected_Start_Date__c", new Date("{!Opportunity_Expected_Start_Date}"));
quote.set("Expected_Delivery_Date__c", new Date("{!Opportunity_Expected_Delivery_Date}"));
quote.set("Account__c", "{!Account_Name}");
quote.set("Billing_Address__c", "{!Account_BillingAddress}");
alert("All quote.set items completed!") // Alert displays
var saveResult = sforceClient.create([quote]);
alert("New Quote Item ID: " + saveResult[0].id); // Alert returns null
}
//-->
</script>
</head>
<body onload="initPage()">
<p>This feature is still under development and not yet implemented. Please click your browsers Back button to return to your opportunity. Sorry for the inconveniene.</p>
</body>
</html>
I appreciate any guidance you can offer. My users are very annoyed at having to do double entry, causing SFDC adoption to decline significantly in my organization.
Thanks and may you have a great day, everyday!
Robert
rstallard@gxt.com
Message Edited by RLStallard-GXT on 10-19-2006 12:59 AM
This should give you some more insight into what is happening. Could be something as simple.
Thanks Sean, I appreciate your help. I added the code you suggested.
Here are the results:
---------------------------------------------------
The Dynabean seems to be retrieving the data correctly.
Here is the screen capture:
---------------------------------------------------
However, there seems to be problems with the saveResult variable.
Here is the capture:
---------------------------------------------------
I don't know how to interpret the error messages nor what to do.
If the Dynabean read the field data correctly, then:
[] Why are there so many false results and an id value of incorrect type?
[] Is it because a picklist selection cannot be passed to an identical picklist field?
[] Is there also a problem with the autonumber text being passed to a text field?
[] If the previous is true, then how do I pass the data in these fields?
[] Do I have any options?
---------------------------------------------------
Thanks so much for any help.
Robert
Message Edited by RLStallard-GXT on 10-18-2006 03:18 PM
Message Edited by RLStallard-GXT on 10-18-2006 03:20 PM
There are several errors causing this:
(1) First, you need to pass the mergefield id not the name when you save your reference back to the opportunity,i.e.
quote.set("Opportunity__c", "{!Opportunity_ID}"); //Master-Detail relationship - Parent Opportunity - Required
(2) Next, you are missing semicolons from several statements, including:
alert("function initPage() and start of createQuote() running good!") // Alert displays
quote.set("Name", "{!Opportunity_Opportunity_Number}") //Standard text field - Name of custom objext - Required - Reading from Autonumber field
quote.set("Opportunity__c", "{!Opportunity_Name}") //Master-Detail relationship - Parent Opportunity - Required
alert("All quote.set items completed!") // Alert displays
quote.set("Opportunity__c", "{!Opportunity_Name}");
quote.set("Opportunity__c", "{!Opportunity_ID}");
Sean and gsickal, your recommendations helped me troubleshoot the code. Thanks so much! I got it to work like a charm. My problem was that I was pulling data to master relationship and lookup fields from the contents of the source fields instead of pointing to the IDs of the source fields.
Here is the final code:
---------------------------------------------------
---------------------------------------------------
When I have a chance, I'll write step-by-step instructions and post these here for the benefit of other newbies like me. If you have any questions in the interim, everyone feel free to contact me by email.
May you have a great day, everyday!
Robert L. Stallard
rstallard@gxt.com
Message Edited by RLStallard-GXT on 10-19-2006 01:12 AM