Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Sunday, August 24, 2025 
 
slxdeveloper.com Community Forums  
   
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!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Avoiding the Application object for Agent tasks?
Mark Hanford
Posts: 131
 
Avoiding the Application object for Agent tasks?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 01 Jul 08 6:52 AM
Greetings all.

I'm running a daily update task as an agent, and currently it's being done in an ancient legacy script. I'd like to convert this to an ActiveScript, but am struggling a bit with some of the DB tasks.

In an ActiveScript, what is the best way of performing database updates and selects when you don't have access to the Application object?

Currently I'm doing stuff like
sql = "UPDATE something SET foo='bar'"
Application.GetNewConnection.Execute sql

And

sql = "SELECT foo FROM bar"
Set lHnd = Application.GetNewConnection.Execute(sql)
SomeVal = lHnd.Fields("foo")

Thanks
[Reply][Quote]
Bob (RJ)Ledger
Posts: 1103
Top 10 forum poster: 1103 posts
 
Re: Avoiding the Application object for Agent tasks?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 01 Jul 08 7:27 AM
The Application Object does NOT exist in the Agent.

You have to construct your own connection string. Otherwise, it's "just ADO".

--
RJLedger - rjlSystems
"...Customer First..."
[Reply][Quote]
Mark Hanford
Posts: 131
 
Re: Avoiding the Application object for Agent tasks?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 01 Jul 08 7:47 AM
Interesting. Okay. I'm trying to keep the main script that does the update common to both the button on the form and the agent-run batch-process (it's a simple "traffic-light" scoring algorythm).

Does the following make sense?

1. An ActiveScript function called "ScoreUpdateOne(AccountID, DBCon)" - this does the calculation for the specified account using the passed ADO con
2. An ActiveScript function called "ScoreUpdate()" - this can be called from a form and uses the CurrentContactID and the default DB stuff to call ScoreUpdateOne
3. An ActiveScript called "ScoreUpdateAgent()" - this pulls a list of ACCOUNTIDs from the DB and calls ScoreUpdateOne

Incidentally, the Agent setup screen seems to ask for a plugin, not a specific function. Which sub does it use; "Main"?
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Avoiding the Application object for Agent tasks?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 01 Jul 08 11:28 AM
Quote:
Originally posted by Mark Hanford

the Agent setup screen seems to ask for a plugin, not a specific function. Which sub does it use; "Main"?


Correct. It will call your Main sub.
[Reply][Quote]
Mark Hanford
Posts: 131
 
Re: Avoiding the Application object for Agent tasks?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 02 Jul 08 5:12 AM
Thanks. I'll put my Agent function in it's own script then, as I imagine having multiple scripts with a Main() included on the same form could cause confusion.

I assume that an ActiveScript run from the Agent can still Include other scripts?
[Reply][Quote]
Bob (RJ)Ledger
Posts: 1103
Top 10 forum poster: 1103 posts
 
Re: Avoiding the Application object for Agent tasks?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 02 Jul 08 6:46 AM
Quote:
Originally posted by Mark Hanford

Thanks. I'll put my Agent function in it's own script then, as I imagine having multiple scripts with a Main() included on the same form could cause confusion.

I assume that an ActiveScript run from the Agent can still Include other scripts?


Yes, it can.
We had a client requirement like yours (run from a button.. and/or run from an agent.)

Here's how we did it:
Create a simple VBscript thet looks like:

sub Main
DoMyThing(False)
End Sub

This will be the VBscript that the agent calls.

Now create another VBscript that has the rest of the code. You will then include that script IN the first one as a normal include script.

...
Dim g_bExecFromSlx

Function DoMyThing(ByVal bExecFromSlx)
g_bExecFromSlx = bExecFromSlx
.... now do your thing.......
''..ex:
If g_bExecFromSlx Then
sCurrentID = Application.Basicfunctions.CurrentUserID
Else
sCurrentID = "ADMIN"
End If

Dim objConn
objConn = GetNewDBConnection
"....
End Function

Function GetNewDBConnection
If g_bExecFromSlx Then
GetNewDBConnection = Connect to db using normal approach
Else
GetNewDBConnection = Connect to db using my own connection string.. since we are running via an agent
End If
End Function


Get the idea?

--
RJLedger - rjlSystems
"...Customer First..."
[Reply][Quote]
Mark Hanford
Posts: 131
 
Re: Avoiding the Application object for Agent tasks?Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 03 Jul 08 8:04 AM
Perfect All working nicely now.
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 8/24/2025 1:08:33 PM