You need to sign in to do that
Don't have an account?
Mathieu DAVOUST
How to duplicate OpportunityLineItems into OrderItems
Hi,
I need to create a button that create an Order from Opportunities. The order created this way will need to be linked to :
I'm not using the Salesforce button because I plan to add the OpportunityLineItem into the order (When the order will be correctly link at the opportunity).
Here is my code :
And there is the error i got:
It's strange because when I make an "insert" with Dataloader (with the same information), it works perfectly.
If I remove the lines that concerne OpportunityId and Pricebook2Id, my button works.
Help needed, every ideas is welcome.
I need to create a button that create an Order from Opportunities. The order created this way will need to be linked to :
- The opportunity's account
- The opportunity
- A predefinied Pricebook
I'm not using the Salesforce button because I plan to add the OpportunityLineItem into the order (When the order will be correctly link at the opportunity).
Here is my code :
{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')} getDate = function(dateObj){ var day = dateObj.getDay() < 9 ? '0' + dateObj.getDay():dateObj.getDay(); var month = dateObj.getMonth() < 9 ? '0' + dateObj.getMonth():dateObj.getMonth(); return dateObj.getFullYear()+'-'+month+'-'+day; } success = function(result) { if (result[0].getBoolean("success")) { alert("new record created with id " + result[0].id); } else { alert("failed to create record" + result[0]); } } failed = function (error) { alert("An error has occurred " + error); } var Commande = new sforce.SObject('Order'); var CommandesAssociees = sforce.connection.query("select Id from Opportunity where Opportunit__c = '{!Opportunity.Id}'"); NbCommandesAssociees = CommandesAssociees.getArray("records"); var CommandeX = NbCommandesAssociees.length + 1; Commande.Name = 'Intervention '+ CommandeX + ' - {!Opportunity.Name}'; Commande.AccountId = '{!Opportunity.AccountId}'; Commande.CurrencyIsoCode = '{!Opportunity.CurrencyIsoCode}'; Commande.EffectiveDate = getDate(new Date()); Commande.Status = 'TestMDAV'; Commande.OpportunityId = '{!Opportunity.Id}'; Commande.RecordTypeId = '01211000000DALj'; result = sforce.connection.create([Commande], {onSuccess : success, onFailure : failed});; location.reload()
And there is the error i got:
It's strange because when I make an "insert" with Dataloader (with the same information), it works perfectly.
If I remove the lines that concerne OpportunityId and Pricebook2Id, my button works.
Help needed, every ideas is welcome.