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
magandrezmagandrez 

Custom VF page with Javascript and Webservice call 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,

Try the below code snippet as reference:

 

<script type="text/javascript">var __sfdcSessionId = '{!GETSESSIONID()}';</script>

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

 

<script>

 

function foundryFromCreatedToAccepted()

{

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

}

 

 

</script>

 

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

magandrezmagandrez

Hi,

 

I tried that, but didn't work. When I press the link no response. The URL bar points to https://c.cs7.visual.force.com/apex/SupplyChainView?id=IDOFTHERECORD# (note the sharp in the end.

 

Do you know how can I debug this? What am I doing wrong?.

 

Thanks Navatar_DbSup