The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Making a global function
Posted: 17 Nov 09 6:12 AM
|
I have a chunk of SQL executed on a button click in which i do a count on an extension table where accountid = 'id'.
If count is 0 i do an insert, if count is 1 i do an update. I thought this would only be used once but i have ended up copying it into 4 forms. How do i make it a global function that can be called from any form script so i dont have to repeat the code? |
|
|
|
Re: Making a global function
Posted: 17 Nov 09 9:07 AM
|
What you can do is use Architect to create a new script file called "c_custom" or whatever name you want - just keep the "c_" to follow standards. Put the procedure in there and then reference this new file in the forms you want to use it. This will give you a lot of flexibility if you change it later on and also allows you to create other global procedures all in the one file. Makes bundling easier as well.
John G. |
|
|
|
Re: Making a global function
Posted: 17 Nov 09 9:13 AM
|
hi john, thanks for your reply. If i create this custom script file and use it to store several functions how would i call one from within a forms script? |
|
|
| |
|
Re: Making a global function
Posted: 17 Nov 09 9:30 AM
|
Sorry i should have worded by question better. What i meant was do you just call it just as 'function name' or do you have to do 'pluginname.scripts.functionname' etc. |
|
|
|
Re: Making a global function
Posted: 17 Nov 09 9:34 AM
|
No need to do that.
On the Script tab of the Form (or on your Script file if using on a VBSCript), you "Include" your script. By including the script, it means that the file gets appended to the actual script before it compiles, so you just need to call your function directly. Do make sure that you don't have conflicting function names.
|
|
|
|
Re: Making a global function
Posted: 19 Nov 09 2:53 AM
|
hi guys, one final question on this:
In my inlcude script i do an sql statement that returns either a count of 0 or 1.
If count is 0 then an insert sql statement is executed that will always be the same so i can have this in my include script.
But if a count of 1 is returned then what sql statement is executed next depends on the form that is calling my function. Will my form script know what count is? so after i call my function i can go straight into "if count = 1" or will i have to return the count from my include script to the form via some code/variable? |
|
|
|
Re: Making a global function
Posted: 19 Nov 09 1:54 PM
|
I would pass a 2nd Parameter, the MODE of the call.....or the Form Name of The Sending Entity.
Then your receiving script can 'know' how to behave... CASE Structure could handle that
Select CASE paramFormName
CASE
CASE
END SELECT |
|
|
|