{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var newRecords = [];
//There is some value present in the text field.
var c = new sforce.SObject("Opportunity");
c.id ="{!Opportunity.Id}";
alert(c.MainCompetitors__c);
//Trying to update opportunity_Status__c (Picklist) with MainCompetitors__c(Text)
c.opportunity_Status__c = c.MainCompetitors__c;
newRecords.push(c);
result = sforce.connection.update(newRecords);
window.location.reload();
/*Trying to update opportunity_Status__c (Picklist) with MainCompetitors__c(Text)**/
4 respuestas
Nadeem,
The c object will neither have a property (aka field ) in the name - MainCompetitors__c nor will it have a value since it is created afresh thro the line - new sforce.SObject("Opportunity"). Do not misunderstand that, such a line brings all the values on the current record into the object - c.
Since, we are on the Opportunity record itself, you can use the merge tag - {!Opportunity.MainCompetitors__c} to retrieve the value in that field for the current Opportunity record. So you will have this:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var newOpptyToCreate = new sforce . SObject ("Opportunity");
newOpptyToCreate.Id ="{!Opportunity. Id }";
newOpptyToCreate.Opportunity_Status__c =
"{!Opportunity. MainCompetitors__c }";
result = sforce. connection . update ([newOpptyToCreate]);
if(result[0].success == "true"){
location. reload ();
}
else{
alert(
"An Error has Occurred: Error: " +
result[0].errors.message
);
}