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
skodisana151887skodisana151887 

How to stop javascript by calling ActionFunction tag

Hi All,

 

I have three action methods in different controllers which inserts records in three different objectsI am invoking the action methods through JavaScript (using ActionFunction Tag). i have some Standard validation rules on the three objects. When i am invoking the first action method using JavaScript, If an exception comes (Validation Rules) the second action method should not invoke.

 

Since it is a JavaScript all the action methods are getting called one by one even though exception(Validation Rules) occurs in the first action methods and error messages on the visualforce screen are being displayed and getting vanished.

 

So please suggest how to stop the JavaScript function if an exception occurs in the controllers.

 

Thanks

Srikanth.K 

 

 

 

AmphroAmphro

If an error occurs in the actionFunction, have your controller set a boolean value. Then in your javascript, you can do something like this.

actionFunction1();
if ({!NOT(error)})
actionFunction2();
juanchibjuanchib

I do that and it dosn't stop it, in fact it always  returns false.

I got this flag in the controller

 

    public Boolean possible { get; set; }

 

And I change it by this actionfunction  

 

<apex:actionFunction action="{!isPosibleNewEvent}" name="isPosibleNewEvent" rerender="isPossible">

<apex:param name="posibleStartTime" assignTo="{!posibleStartTime}" value="" />

<apex:param name="posibleEndTime" assignTo="{!posibleEndTime}" value="" />

</apex:actionFunction> 

 

And i have this logic at the javascript

 

isPosibleNewEvent(st.getTime(),ed.getTime());

alert({!possible}) ;

   if({!possible)

        jQuery("#gmCalendarNewEvent").show(); 

 

And the alert always shows false, any idea? or other way to do this !? thanks

AmphroAmphro

What your doing should work, I would need to see your apex code.

 

juanchibjuanchib
First of all, thanks for the quick reply! The code is quite a mess and I can't post it all, but I wonder if this problem can come from the pagerefernce I return from the action function, since I am returning null? 
AmphroAmphro

No problem. Well, my first general advise is to clean up the code. Typically, a good refractor of the code can fix hidden spots where the bug originally hid or make it so you can easily pin point where the bug is. 

 

The pagereference shouldn't matter. If you return null it tells visualforce to stay on the page. However since you are using it in an actionfunction and not an actionlink or actionbutton, I would make it void. 

 

Another thing to make sure is that your apex:params tags are setting properties and the function within apex is parameterless. I am assumming you are doing this but I made that mistake at one point.

 

Since you don't want to post the code, print out some values in the console. Print out the values of start and end time within the apex code, and any other usefull information. It may help you narrow down what it is actually doing.