+ Start a Discussion
magandrezmagandrez 

Apex WService + custom VF + custom Javascript link not working

Hello,

 

I have a WS that changes the value of one field using Javascript. something like this:

 

WS:

 

global class fromMSStatusAToB{

WebService static void changeStatus(String id, String status) {

    // update a status field.             
}
}

 In the layout I lifted a button with this code that works normally:

 

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")} 
sforce.apex.execute("fromMSStatusAToB","changeStatus",{id: "{!Process_Cost__c.Id}" ,status:"Accepted"}); 
alert('MS Status updated'); 
window.location.reload(true);

 This works normally. But now the requirements changed and I need to put this on a custom VF page. To meet that requirements I put in the VF the following code to call the Apex WS:

 

<script src="/soap/ajax/15.0/connection.js" type="text/javascript"</script>
<script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>

<script>
function foundryFromCreatedToAccepted(){
sforce.apex.execute("fromMSStatusAToB","changeStatus",{id: "{!Process_Cost__c.Id}" ,status:"Accepted"}); 
}

</script>

 And I call this function with a command link like this:

 

<apex:commandLink value="Change Status to Accepted" onclick="foundryFromCreatedToAccepted()" />  

 

The problem is that all code is saved, but it doesn't seem to work. Do you have any ideas why it doesn't work? Any workaround? How can I debug this kind of problems?

 

Many thanks,

 

MGA.

Navatar_DbSupNavatar_DbSup

Hi,

 

You are calling the wrong function that is not in page.

 

Try the below code snippet as reference:

 

<apex:commandLink value="Change Status to Accepted" onclick="foundryFromCreatedToFwEng()" />

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

magandrezmagandrez

Sorry, I edited wrong the code. It looks like the one you posted, and it doesn't work either.

 

Any other view on this? Any help is very welcome.