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
tjateurotiretjateurotire 

Using S-control to convert Picklist value to text

Because of the constraints around using picklist values in formulas (ie. only CASE and ISPICKVAL are available) I found a solution which takes a picklist value and returns that value as text in another field. Or at least this is what the post claims this code is supposed to do. I can not get this thing to work however, and was wondering if the code is still valid. When I place the s-control on the page layout, it is certainly there... and when I go to s-control dependencies it shows that the s-control is dependent on the picklist field, but it does not copy the picklist value to the other custom field (which by the way I have created as a standard text field). Am I missing something? Is this code still valid?

Below is a direct copy/paste from salesforce.

This can be used for long picklists, or picklist that are often changed. It allows to bring the text value of a picklist into a custom field.

Object on which the control is applied:  "Target__c"

Name of the picklist field: "Mill_1_Style__c"

Name of the field on which we copy the value from Mill_1_Style__c: "Right__c"

 

S-Control:

<html>
<head>
<link href="/sCSS/8.0/1171411121000/Theme2/default/common.css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" type="text/css" />
<script src="/soap/ajax/8.0/connection.js"></script>
<script>
var FieldLabelofFieldToUpdate = "Right";
function initPage() {
var tarx= new sforce.SObject("Target__c");
tarx.Id="{!Target__c.Id}";

newAmt= "{!Target__c.Mill_1_Style__c}"

resultGo = sforce.connection.update([tarx]);
setTDInnerHTML(newAmt);
document.body.innerHTML = "";
}
function setTDInnerHTML(val)
{
var d = window.parent.document;
var tds = d.getElementsByTagName("TD");
for(var i=0; i<tds.length; i++)
{
if(tds[i].innerHTML == FieldLabelofFieldToUpdate )
{
tds[i].nextSibling.innerHTML = val;
}
}
}
</script>
</head>
<body bgcolor="#F3F3EC" onload="initPage();">
</body>
</html>


werewolfwerewolf
I'm not sure what you're doing there actually, but if you want to set another field to a value matching that of a picklist I'd suggest you use an Apex trigger instead.
tjateurotiretjateurotire
My organization does not have an edition of Salesforce which accommodates Apex triggers.

So the question remains: Is there a way to use an S-control, to copy a field value from a picklist (or any other field type, such as a result from a formula) to a different field. I want to do this because:

1) Using the picklist operators is annoying and time consuming
2) Because I'm using picklist operators in some of my formulas, and because the picklists I'm using are very long, I'm running into the ceiling for numbers of characters which can be computed (5000 total for formulas which reference other formulas).


Thanks again for your help.
werewolfwerewolf
If you don't have Apex triggers then I assume you don't have the API either.  The only way I can think of to do what you want to do here is to use the API in an S-control -- but if you could do that then you could write an Apex trigger also, which would be vastly better anyway.
jhamletjhamlet

I am struggling with this as well with some very long picklist values.

I would love to see some sample code if anyone has done this with an Apex Trigger (learning myself) or a working S-Control.  I am sure that it would be pretty short, right?

Thanks!