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
Steve HarrisonSteve Harrison 

Need on-click javascript

We have a custom button that generates an invoice record from an order. I would like to automatically update the order Status field to "Invoice Sent" when that button is pressed. Below is the current script for the button. Can someone provide additional javascript to add this update?  

Thanks!

Steve

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

var id = sforce.apex.execute("AdaptiveUtilities", "invoiceFromOrder", 
                             {orderId: '{!Order.OrderNumber}'});

window.location = "/" + id;
Best Answer chosen by Steve Harrison
KaranrajKaranraj
Below is the code which will updade the status field in order object also, pls verify
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

var id = sforce.apex.execute("AdaptiveUtilities", "invoiceFromOrder", 
                             {orderId: '{!Order.OrderNumber}'});
var ord = new sforce.SObject("Order"); 
ord.id = "{!Order.Id}"; 
ord.Status = "Invoice Sent"; 
sforce.connection.update([ord]); 
window.location = "/" + id;


 

All Answers

KaranrajKaranraj
Below is the code which will updade the status field in order object also, pls verify
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

var id = sforce.apex.execute("AdaptiveUtilities", "invoiceFromOrder", 
                             {orderId: '{!Order.OrderNumber}'});
var ord = new sforce.SObject("Order"); 
ord.id = "{!Order.Id}"; 
ord.Status = "Invoice Sent"; 
sforce.connection.update([ord]); 
window.location = "/" + id;


 
This was selected as the best answer
Steve HarrisonSteve Harrison
That did it!  Thanks Karanraj!