+ Start a Discussion
neerureddyneerureddy 

Problem in concatenating firstname and lastname

Hi ,

 

I have candidate__c is a custom object. It has firstname,last name and full name  custom fields. I want to do concatenation of firstname and last and want to display it in fullname when click a button called GetFullName.

 

 

For this,

 

I have created custom button called GetFullName. and written S-control to attach to the that button. Here I am facing problems. I cant assign concatenating value to the fullname field. Can any one suggest me how can I accomplish this task. I was tried doing but i cant.

 

Here is the s-control code:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<!-- <script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/13.0/connection.js"></script>
<script src="/soap/ajax/13.0/apex.js" type="text/javascript"></script>
-->
<script language="javascript">

    var candidateId = "{!Candidate__c.Id}";

    var fname= "{!Candidate__c.First_Name__c}";
    var lname= "{!Candidate__c.Last_Name__c}";
    var fullname= fname + ' ' +lname ;
function merge()
{
   alert( fullname);
   window.parent.location.href = "/" + candidateId ;
 
}

</script>
</head>
<body onload="merge()" >
</body>
</html>

 

Thanks in Advance.

 

BeeddiskShahBeeddiskShah

Erm, friend, A quick question, do you know something called 'Formula field'?? Just curious. Well, if you have no clue, then go explore it.

 

Second thing, know anything about 'Triggers' well these are two things that can help you  achieve this functionality.

 

Go explore buddy, and hullo S-control is old-school, the closest you can get with the 'deadly' idea you are trying to implement above, you can go for on-click javascript.

 

 

neerureddyneerureddy

Hi Ravan,

 

 

Thanks for your information.but, I want to do it by writing code. Even if I used S-control, inside i have used java script function only. If i go for onclick javascript then also I have to do same thing . Could please let me know how we can assign concatenated value to a field on the form in onclickjavascript.

 

Aprreciate your help.

 

thanks,

Neeru.

CaptainObviousCaptainObvious

If you're using the ajax toolkit, you need to update the record. Modify your merge function as follows:

function merge() { alert( fullname); //Update the Candidate Record var candidateUpdate = new sforce.SObject("Candidate__c"); candidateUpdate.id = candidateId; candidateUpdate.Full_Name__c = fullname; var saveResult = sforce.connection.update([candidateUpdate]); if(saveResult[0].getBoolean("success")==false) { alert('There was an error:' + saveResult); } else { top.location.replace("/{!Candidate__c.Id}"); } }

 

As suggested, you should really try to migrate away from s-Controls and do this using a formula, Workflow field update, or an Apex Trigger.

neerureddyneerureddy

Hi Captain,

 

I am very thankful to you. Now the code is working and giving result as expected. As I am new to SFDC i am trying on my own by taking some tasks. As suggested i will use Apex triggers or Workflow field update only.

 

Thanks,

Neeru.

jbardetjbardet

but those of us stuck in Professional Edition, what are we to do? Stick with S-controls?