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
Shamus Kelley 4Shamus Kelley 4 

How can I modify this OnClick JavaScript so that it will also mark a custom checkbox field True while processing?

I have this OnClick java button that I need to modify so that it also marks a custom field True while processing. Here is the current code:

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

// Call the web service method to display the Email Author JSP page for 
// the Work Order email template. Result is an object with success="true" or "false" 
// and msg = "error message or other string." 
try { 
var result = sforce.apex.execute( 
'Work_Order_Buttons', // class name 
'sendWorkOrder', // methodName 

oppIdraw: "{!Work_Order__c.Id}" 

); 
if (result[0].success == 'true') { 
window.location.href = result[0].msg; 

else { 
alert(result[0].msg); 


catch (ex) { 
alert("Error: " + ex); 

any help is appreciated! thank you- 
GauravGargGauravGarg
Hi Shamus,
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var p = new sforce.SObject('!Work_Order__c'); 
p.id = "{Work_Order__c.Id}";
p.Status__c = "Value"; 
result = sforce.connection.update([p]); 
location.reload(true);


Please update the code as per the requirement. 

Thanks,

Gaurav
Skype: gaurav62990
 
Shamus Kelley 4Shamus Kelley 4
@GauravGarg - 

Thank you for the quick help. I'm now getting an error when trying to processing the button. 

I updated the code as follow:

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

var p = new sforce.SObject('!Work_Order__c');
p.id = "{Work_Order__c.Id}";
p.Sync_to_Epicor__c = "true";
result = sforce.connection.update([p]);
location.reload(true);

// Call the web service method to display the Email Author JSP page for 
// the Work Order email template. Result is an object with success="true" or "false" 
// and msg = "error message or other string." 
try { 
var result = sforce.apex.execute( 
'Work_Order_Buttons', // class name 
'sendWorkOrder', // methodName 

oppIdraw: "{!Work_Order__c.Id}" 

); 
if (result[0].success == 'true') { 
window.location.href = result[0].msg; 

else { 
alert(result[0].msg); 


catch (ex) { 
alert("Error: " + ex); 
}


I'm getting the following error message:

{faultcode:'sf:INVALID_TYPE',faultstring:INVALID_TYPE:sObject type 'Work_Order__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. ', detail:{InvalidSObject type '!Work_Order__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. ', row:'-1', column: '-1',},},}

did I place your script in the wrong area? not sure how to proceed. 

thank you- 

 
GauravGargGauravGarg
Hi Shamus,

Please check the Object API name, it should be "work_order__c" if it different please update in script call. 
 
{
    !REQUIRESCRIPT("/soap/ajax/29.0/connection.js")
} {
    !REQUIRESCRIPT("/soap/ajax/25.0/apex.js")
}

// Call the web service method to display the Email Author JSP page for 
// the Work Order email template. Result is an object with success="true" or "false" 
// and msg = "error message or other string." 
try {
    var result = sforce.apex.execute(
        'Work_Order_Buttons', // class name 
        'sendWorkOrder', // methodName 
        {
            oppIdraw: "{!Work_Order__c.Id}"
        }
    );
    if (result[0].success == 'true') {
        window.location.href = result[0].msg;
        p.id = "{Work_Order__c.Id}";
        p.Sync_to_Epicor__c = "true";
        result = sforce.connection.update([p]);
    } else {
        alert(result[0].msg);
    }
} catch (ex) {
    alert("Error: " + ex);
}

Please check and let me know if you still face some error. 

Thanks,
Gaurav
Skype: gaurav62990
Shamus Kelley 4Shamus Kelley 4
Hi Gaurav

For some reason its still producing an error. I've used your latest script and the error message is now stating " REQUIRESCRIPT not defined".