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
Linda 98Linda 98 

Urgent help needed with custom button.....Please

HI..

 

I am trying to write a custom button with Onclick javascript..

 

On click of button on OpportunityLineItem i want value from my custom field to be copied to standard field(Unit price) 

 

Here is my code...

 

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

Var OppId={!GETRECORDIDS( $ObjectType.OpportunityLineItem )};

var Opp = new sforce.SObject("OpportunityLineItem");
Opp.Id = OppId ;
Opp.UnitPrice = "{!OpportunityLineItem.Customfield__c }",replace ',' -->;
updateRecords.push(Opp);
result = sforce.connection.update(updateRecords);

 

 

I get Unexpected identifier when i click on the button...

 

Please help

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Linda 98Linda 98

I got the solution...This worked....

If any1 need it....

 

 

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
var newRecords = [];
records = {!GETRECORDIDS($ObjectType.stdObject/customObject)};
for (var n=0; n<records.length; n++) {
var c = new sforce.SObject("StdObject/custom object");
c.id = records[n];
var qr = sforce.connection.query("Select customfield__c From StdObject where id ='"+c.id+"' ") ;
r = qr.getArray("records");
if (records.length > 0)
{
var price = r[0].get("customfield__c");

c.stdfield/field i want to update= price;
}
newRecords.push(c);
}
result = sforce.connection.update(newRecords);
window.location.reload();

 

 

All Answers

Sekha(Devlope)rSekha(Devlope)r

Hi There,

 

You can achieve this funcitoanlity in VF page by using "document.GetElementByID" to get the custom field value and you can update standard field.

 

Let me know if you need further help.

 

Thakns,

RajSF

Linda 98Linda 98

But it is a standard page....And i am using professional....custom button will not help???

 

On top of everything...Can i update UnitPrice???

Bhawani SharmaBhawani Sharma

I remember Professional edition doesn't support API. You can't  do this with custom button.

Linda 98Linda 98

But its like writing Javascript....I am having Mass delete custom button in my organization...and it works perfect....

 

 

 

paulo.orquillopaulo.orquillo

The javascript unexpected identifiier error is likely from this line.

 

Opp.UnitPrice = "{!OpportunityLineItem.Customfield__c }",replace ',' -->;

If you want to use replace method, syntax is something like

 

string.replace(searchvalue,newvalue)

 

but if you only want to retrieve the custom field value try

 

Opp.UnitPrice = '{!OpportunityLineItem.Customfield__c}';

 

Linda 98Linda 98

I tired that..and it errored out saying

 

Error: {faultcode:'soapenv:Client', faultstring:''' is not valid for the type xsd:double', }

 

So i used that ..

 

Thanks

Linda 98Linda 98

I got the solution...This worked....

If any1 need it....

 

 

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
var newRecords = [];
records = {!GETRECORDIDS($ObjectType.stdObject/customObject)};
for (var n=0; n<records.length; n++) {
var c = new sforce.SObject("StdObject/custom object");
c.id = records[n];
var qr = sforce.connection.query("Select customfield__c From StdObject where id ='"+c.id+"' ") ;
r = qr.getArray("records");
if (records.length > 0)
{
var price = r[0].get("customfield__c");

c.stdfield/field i want to update= price;
}
newRecords.push(c);
}
result = sforce.connection.update(newRecords);
window.location.reload();

 

 

This was selected as the best answer