function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jchenjchen 

Using S-Control to show web phone and populate the feild data from the contact phone?

Hello guys, couldn't post using Graphics Editor somehow. I solved some of the issues, but can't figure out the rest. Here is what I do so far. I have a new Edit button that when I click, it will populate Web Company with some value, so the web feilds will show up, and then, open the edit page. I also copied contact info to web feilds if availible.

Now the problem is this. This only works if there is already a case. It is not a New button. How do I make a new button to show web fields? And is there a better to show web fields? So far I just put a value in one of the web feilds to do that, but it doesn't feel right.

Code Here:

{!REQUIRESCRIPT("/soap/ajax/9.0/connection.js")}
var CaseDetails= sforce.connection.query("select Id from Case where Id= '{!Case.Id}'");
var CaseArray = CaseDetails.getArray("records");
var CaseRec =new sforce.SObject("Case");
CaseRec.Id= CaseArray[0].Id
if("{!Case.SuppliedCompany}" == "" || "{!Case.SuppliedCompany}" == null)
  CaseRec.SuppliedCompany= "show"

var ContactDetails= sforce.connection.query("select Id, Name, Email, Phone from Contact where Id = '{!Case.ContactId}'");
if (ContactDetails.size > 0){
  var ContactRec = ContactDetails.getArray("records")[0];
if("{!Case.SuppliedName}" == "" || "{!Case.SuppliedName}" == null)
  if(ContactRec .Name != null)
    CaseRec.SuppliedName= ContactRec .Name;
if("{!Case.SuppliedEmail}" == "" || "{!Case.SuppliedEmail}" == null)
  if(ContactRec .Email != null)
    CaseRec.SuppliedEmail= ContactRec .Email;
if("{!Case.SuppliedPhone}" == "" || "{!Case.SuppliedPhone}" == null)
  if(ContactRec .Phone != null)
    CaseRec.SuppliedPhone= ContactRec .Phone ;

//alert(ContactRec .Id + " , " + ContactRec .Name + " , " + ContactRec .Email+ " , " + ContactRec .Phone);
//alert(CaseRec.Id + " , " + CaseRec.SuppliedName+ " , " + CaseRec.SuppliedEmail+ " , " + CaseRec.SuppliedPhone);
}
if(! sforce.connection.update([CaseRec ])[0].getBoolean("success"))
     alert("Web Field Update Failed!");
//window.location.reload();
window.parent.location.href = "{!URLFOR($Action.Case.Edit, Case.Id, [retURL=URLFOR($Action.Case.View, Case.Id)], true)}"

Message Edited by jchen on 10-05-2007 04:57 PM