Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do validations only allow true or false
#11
I tried it again:

Validation map

   

the script with the function:  modules/Accounts/myvalcode.js

function mysupervalidationfunction(edit_type, formName, action, callback, params) {
console.log(edit_type, formName, action, callback, params);
alert('custom validation');
}


the business action to load the javascript

   

the result

   
Joe
TSolucio
Reply
#12
OK, so following that I could get it to work, but it doesn't quite do what I want. First of all, it didn't work when I setup the map like this (shortened for brevity)
Code:
<validations>
    <validation>
        <rule></rule>
        <restrictions>
            <restriction></restriction>
        </restrictions>
        <message>%%%FUNCTION%%%checkAccountAddress%%%PARAMS%%%{field},lbl</message>
    </validation>
</validations>
because apparently the rule and restrictions can't be empty. But do they have to contain just something, or specific stuff?

Secondly, the way I like it better is like in the blogpost, where it's not a businessmap that fires the validation but a business action in the form of a presave event hook. That way, I can immediately collect and send the account address and the result (does the account address match the address on the salesorder). Now I would have to fire a custom AJAX call to get the account information, compare that to the onscreen stuff and then do the rest. Is it correct to assume that we can use custom functions to validate through either a business map or a presave business action?
Reply
#13
I'm not totally following but I'd say yes: just use a presave business action
Joe
TSolucio
Reply
#14
Well, the initial assignment I got is: When a salesorder is saved, make sure the shipping address corresponds with the one on the account and provide a dialog to overwrite the salesorder shipping address when it doesn't correspond.

So I like the backend stuff (for which I understand I can choose between a business map and a presave business action) to look in the database, check the account and see if the addresses correspond. Now using a presave business action I can do that. I receive the context, can do a DB lookup, see if the addresses correspond and respond with some information that my frontend JS function can understand and deal with.

I can't perform that same validation in the business map, in stead I would have to make my JS do an AJAX call to some lookup code I would have to write on the backend, return that and then prompt the user when necessary. Seems like double work when I can also use a businessaction to do that work, but that's where the problem is: business actions don't seem to work for me, so I'd like to know why and how I can fix that.
Reply
#15
ok, I think I understand where you are missing the issue. there are two presave events

- a PRESAVE business action which is a JAVASCRIPT front end call that will be made BEFORE sending the fields in the form to the backend, this can be done using the Business Action or (now) also as a result of a validation map

- a PRESAVE corebos event that is a PHP script that will be called before executing the actual save in the DB, once all the fields have been submitted to the corebos, this event handler can return a "false" state in which case all the information will be resent back to the front end with an error message

https://github.com/tsolucio/corebos/blob/master/modules/Vtiger/Save.php#L95
https://github.com/tsolucio/corebos/blob/master/data/CRMEntity.php#L1201

you can do what you need to do in either, the JS frontend, effectively will require some ajax backend call to get the information from the backend while the event handler in the backend will require a round trip of all the information to the backend and back
Joe
TSolucio
Reply
#16
OK, so when I create a business action of type 'PRESAVE', what am I creating? Is that the
Quote:PRESAVE business action which is a JAVASCRIPT front end call
or the
Quote:PRESAVE corebos event that is a PHP script that will be called before executing the actual save in the DB
Reply
#17
business actions are mostly UI oriented, they add a button, link, widget or load some code in the front end while events are backend oriented adding functionality at key points of the execution of the code

if you look at the example a few post above you see that I created a business action to load a custom javascript file in the frontend that is called by the validation process.

So, in short: a presave business action is loading some javascript code to be called in the frontend when the user clicks on the save button
Joe
TSolucio
Reply
#18
OK. So how about the XML:

Code:
<validations>
   <validation>
       <rule></rule>
       <restrictions>
           <restriction></restriction>
       </restrictions>
       <message>%%%FUNCTION%%%checkAccountAddress%%%PARAMS%%%{field},lbl</message>
   </validation>
</validations>
The above won't work since there's nothing in the <rule> or <restriction>. What needs to be in there? Just anything or specific stuff like 'contains' or 'mex'?

Sorry, but both versions aren't working for me. First of all: what I did in a recent installation:
Validation map on SalesOrders
   
Then the business action
   
Which points to JS code
PHP Code:
function checkAccountAddress(edit_typeformNameactioncallbackparams) {
    
console.log(edit_typeformNameactioncallbackparams);
    
alert('test');

Resulting in
   
No logging to the console and an empty alert. I checked the buffer through the network tab, it loads the JS properly.

The second method, using a PRESAVE business action, I still don't understand. Take these steps:
  • I go to business actions
  • I create a new one
  • I select type PRESAVE
  • I set some 'block://className:filePath' as the URL
  • I save the business action
Then what happens? Does something happen on both inline edit as full save? Is there any way the 'process' method can allow the save to continue? In the blogpost it returns a function name but can it also say 'Ah OK I'm not complaining, proceed saving'?
Reply
#19
I don't even understand how your example works for you, since when I replicate it exactly it only asks me to make sure the accountname contains 'mex', which is exactly what you would expect. Then when I make sure the accountname contains 'mex', it just saves.
Reply
#20
the second is NOT a buisness action: it is an event handler, it is done in the code: https://github.com/tsolucio/corebos/blob/master/build/HelperScripts/coreBOSEventsLoader.php#L19

as to the first method, forget about it: create a custom validation script like you did for the inventory modules and do whatever you want
Joe
TSolucio
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)