• No results found

User Defined Scripts

In document TSM API Version 2.11 (Page 47-60)

UDF_DELETE_<tablename> (lIgnoreError,oGlobal) Run before commiting deletion a record

Return false to

UDF_New_<tablename> (lIgnoreError,oGlobal,oThisform) Run on appending a record

Return false to prevent appending of a record.

Used for custom security, or custom defaults.

UDF_NEW_Servcard (IgnoreError,oGlobal,oThisform) Run on appending a new job record

UDF_Servcard (lIgnoreError,oGlobal,oThisoform,cAction) Run during update of job

Return false to refuse to update

UDF_SAVE_SERVCARD (nServcardid,lNewJob,oGlobal,oThisform,lIgnoreError) Run after update of job records.

Used to trigger

UDF_Pre (lIgnoreError,oGlobal,oThisform,cAction) Run before update.

UDF_<tablename> (oGlobal,lIgnoreError,oGlobal,oThisform,cAction) Run before committing records.

Return false

Useful for validation and triggering event based on buffered changes

UDF_SAVE_<tablename> (lIgnoreError,oGlobal,lAdd,oThisform) Run after Save

UDF_Backup (oGlobal,lFtp,mCheckit) Run after backup

UDF_RunDocument (oGlobal,cFileName,cWorkDir,cOperation)

Run when running a document. Allows you to create your custom launcher

UDF_INIT_SS (oGlobal,cDomanUser,cDomain,cDomainPassword) Run when initialising INIT_SS

UDF_Customer_LostFocus (oGlobal,oThisform,oGlobal,lAuto) Run when customer ID changes

UDF_Site_LostFocus (cSiteID,oGlobal,oThisform,oGlobal,lAuto) Run when Site Customer changes

UDF_Complete_Required (oGlobal) Run when Completing

Return .T. to allow completion even if required checklist questions unanswered

UDF_Complete_Servcard (lAuto,oGlobal,oThisform,cAction) Run on complete

UDF_After_Complete_Servcard (lAuto,oGlobal,oThisform,cAction) Run after job complete

UDF_SendMessage (nServicardid,cCustomerID,cFromaddr,cEmail,cCCAddress, cBCCAddress,cSubject,cBody,cmailserver,cAccount,cPassw ord,cAttachments,nBodyFormat,lNoBody,cRecipient,mform Type,cFromAddrNoName,cfromname,oGlobal)

Run prior to sending an email. All paramaters passed by reference to allow changes any of the settings.

UDF_SendMail

Create your own custom email sending method

UDF_LinkDocList (oGlobal,nServcardid,nStageseq,nVarseq,cGridCursor) Used to create your own grid cursor or update the current grid cursor

UDF_PrintInv (oGlobal,oThisform) Run prior to printing invoice.

Return false to prevent printing of the invoice

UDF_PrintInv_After (oGlobal,oThisform) Run after printing invoice

UDF_MoveAsset (oGlobal,nSeq,nServcardid,lMoveChildren,nIncSchedules) Run prior to moving assets

UDF_ChkStru ()

Run at end of Structure Check

Enables you to to customer database cleanup, or enforce structural changes

UDF_SAVEEML (oGlobal,oMailObject,oMessageObject) Run after creating an EML file.

UDF_TOTALSERVCARD (lUpdate,nServcardid,nStageseq,lNoMinCharge) Run after calculating job total

NewCustCode (cName)

Custom code to generate a Customer ID on customer creation

UDF_SetMemvar (oGlobal)

Run at end of setting global memory variables / properties

UDF_UPDCUSTOMERID (cOldKey,cNewKey,cAPName,cAPListID) Run at end of updating Customer Key

UDF_UPDPRODUCTID (cOldKey,cNewKey,cAPName,cAPListID) Run after changing Product ID

TSMAfterLogin() Run after logging in

UDF_CustProdDisc()

Run after calculating product discount. Returns discount

udf_regocx()

Run after registering OCX files.

Use to register other things.

UDF_LAUNCH (oGlobal,cURL,cPArams,cDir,lRunAs,nView) Custom launcher

TSMStartUp()

Runs when TSM starts up but before login

TSMAfterLogin() Runs after login

UDF_Reindex() Runs after reindex.

Used for adding custom indexes, such as on user defined fields

XML File to Process

(emailbody,MailDate,htmlBodyStr,@cError,AttachmentXML ,MailAddress,MailSubject,MailFrom,@lNoEmail,emailtext,o Thisform)

Parses inbound data in XML Processor

UDF_XMLPROCESSOR.PRG (oGlobal,oThisform) Runs after processing XML inbound data

UDF_JCINV (lIgnoreError,oGlobal,oThisform) Runs after opening Contracts Jobs Invoice screen.

UDF_MakeCard (nServcardid,cAutoPONumber) Runs after processing maintenance schedules.

Used to trigger processes from maintenance jobs, but not other jobs.

TSMGRIDS_MAKECARD.INI (oGrid,oThisform)

Run directly after creating the Schedules grid to add additional columns to the grid

UDF_INIT_TSMFormSet (oGlobal)

Runs at beginning of Initialising TSM screen

UDF_REFRESH_TSMFormSet (oGlobal)

Run directly after refreshing the main TSM Window

The following is a sample VB application indicating the use of the TSM.DLL

'Visual Basic Sample code For TSM com interface

Dim objTSM as object Dim bResult as boolean

' Initialise TSM object

objTSM = CreateObject("TSM61.Global")

' Setup TSM object environment

If not objTSM.TSM_Init("JT","","C:\tsm") then MsgBox("Login Failed")

Exit Sub End If

' Read the name of the customer in the customer table in the first record text1.text = objTSM.TSM_Read("Customer","FirstName") & " " &

objTSM.TSM_Read("Customer","LastName")

' Close the customer table

bResult = objTSM.TSM_Close("Customer")

' Release the TSM object objTSM = Nothing

VB Sample Code for adding a job into TSM

Dim objTSM As object

repValue = objTSM.TSM_Init("JT","","C:\TSM")

‘ Add a new job and return the job number jobNo = objTSM.TSM_AddJob()

‘ Replace the fields in the job with desired values

repValue = objTSM.tsm_replace("Servcard", "COMPANY", Trim(tempRec("Name")))

repValue = objTSM.tsm_replace("Servcard", "JOBDATE", "%%CTOT('" &

tempRec("Commence_Date") & "')")

repValue = objTSM.tsm_replace("Servcard", "DATECOMP", "%%CTOT('" &

tempRec("Complete_Date") & "')")

repValue = objTSM.tsm_replace("Servcard", "DATE", "%%CTOT('" &

tempRec("Commence_Date") & "')")

repValue = objTSM.tsm_replace("Servcard", "CUSTCONT", Trim(tempRec("Tele_Comment")))

repValue = objTSM.tsm_replace("Servcard", "MOBILE", Trim(tempRec("Tele_Comment2")))

repValue = objTSM.tsm_replace("Servcard", "SERVREQUES", Trim(tempRec("Fault")))

repValue = objTSM.tsm_replace("Servcard", "WORKPERF", Trim(tempRec("Comment")))

repValue = objTSM.tsm_replace("Servcard", "STATUSCODE", Trim(tempRec("Status")))

‘ Save the job and check if successful If Not objTSM.tsm_savejob(jobNo) Then

MsgBox objTSM.lasterror End If

VB Sample Code for to initialise the TSM API session ' noTSM is the current session object

Private Function zInitTSM() As Boolean

' If there is already a current session then select it and do not open a new session.

If Not Session("moTSM") Is Nothing Then moTSM = Session("moTSM")

Return True End If

Dim bResult As Boolean = False Dim sFolder As String

' Initialise TSM object

moTSM = VB.CreateObject("TSM61.Global")

' msUSername is a variable holding the TSM login name ' msPassword is a variable holding the TSM login password ' msFolder os the path to the TSM directory

bResult = moTSM.TSM_Init(msUserName, msPassword, msFolder)

If bResult Then

' Create a new session Session("moTSM") = moTSM

End If

Return bResult

VB Sample Code to position the record pointer on a particular job '

TSM_Seek(12345,"ServCard","servcardid",false);

* Function to Seek a value in a table

Public Function TSM_Seek(ByVal eExpression As String, ByVal cTableAlias As String, ByVal cTagName As String, ByVal lNoMovePointer As Boolean) As String

Try

Dim bResult As Boolean = False If zInitTSM() Then

bResult = moTSM.TSM_Seek(eExpression, cTableAlias, cTagName, lNoMovePointer) End If

Return bResult.ToString + "," + moTSM.LastError Catch ex As Exception

Return ExceptionMessage End Try

End Function

VB Sample Code to return an SQL query from the TSM API as XML

XMLString = TSMQuery("SELECT * FROM Time WHERE ServCardID == " & servcardid & "

ORDER BY [Date],Start")

Public Function TSMQuery(ByVal Query As String) As String Try

Dim ds As Data.DataSet = Nothing Dim oXML As New XmlDocument If zInitTSM() Then

Dim iRows As Integer Dim sXML As String

' Pass the query to the API and create an API side cursor iRows = moTSM.TSM_Query(Query & " into cursor MyRes")

' Convert the results into XML and get XML sXML = moTSM.TSM_ToXML("MyRes") oXML.LoadXml(sXML)

' Don’t forget to release the API side cursor moTSM.TSM_Close("MyRes")

End If

Return oXML.InnerXml Catch ex As Exception Return ExceptionMessage End Try

End Function

VB Sample Code to update the customer note field

' First parameter is the CustomerID to look up, the 2nd value is the note text to write

Update_CustNote(“ACME”, “This is the new note string”);

Public Function Update_CustNote(ByVal customerID As String, ByVal note As String) As String

Try

Dim bResult As Boolean If zInitTSM() Then

' Query the customer unique key Seq

moTSM.TSM_Query("SELECT seq FROM Customer WHERE CustomerID == '" &

customerID & "' INTO CURSOR MyRes")

' Read the Seq from the cursor

Dim seq As Integer = ToInteger(moTSM.TSM_Read("MyRes", "seq"))

'Close open cursor

moTSM.TSM_Close("MyRes")

' Position the actual customer record pointer

If moTSM.TSM_Seek(seq, "Customer", "seq", False) Then ' Replace customer note

moTSM.TSM_Replace("Customer", "NOTE", note) End If

' Commit your changes

bResult = moTSM.TSM_TableUpdate("Customer", "EDIT", , , True) End If

‘ The following is also functionally similar:

Public Function Update_CustNote(ByVal customerID As String, ByVal note As String) As String

Try

Dim bResult As Boolean If zInitTSM() Then

' Query the customer unique key Seq

moTSM.TSM_Query("UPDATE Customer SET note = “ & note & “ WHERE CustomerID == '" & customerID & "')

' Commit your changes

bResult = moTSM.TSM_TableUpdate("Customer", "EDIT", , , True)

End If

In document TSM API Version 2.11 (Page 47-60)

Related documents