This topic is locked

Calling / Executing SQL Server 2000 Stored Procedures

1/18/2006 3:25:06 PM
ASPRunnerPro General questions
C
clig author

For example you have a field named "Status" with a value of 1 or 2 (Open or Closed) - Something simple such as setting the date in a text field can be performed by adding an "onclick" event to the save button based on an IF condition in a function located in jsfunctions.js...
Has anyone tried initiating one or more stored procedures based on similar criteria. Say for example the record now has a "Status" value 2 (Closed) - when saving the record the record needs to be moved to another table alonf with any records in a dependant child...
V. 3.2
thanks

Sergey Kornilov admin 1/18/2006

You need to use Events in ASPRunner 4.0. Events are desinged specifically for this purpose.

C
clig author 1/19/2006

You need to use Events in ASPRunner 4.0. Events are desinged specifically for this purpose.


Ok thanks - So testing this out - the code is stored in: include/xxx_events.asp
eg)
<%
Sub AfterEdit()

'** Insert a record into another table ****

strSQLInsert = "INSERT INTO dbo.[Clsd_TS_Ticket_Referral] ([Service Record ID], [Project], [CSR], [Sims], [ServiceDate], [ProblemDescription], [Status], [Technician], [Tech Support], [Resolution Date], [Priority], [Severity], [Last Modified], [TechSuppRegion], [Technician1], [ExtraDetail]) VALUES ([Service Record ID], [Project], [CSR], [Sims], [ServiceDate], [ProblemDescription], [Status], [Technician], [Tech Support], [Resolution Date], [Priority], [Severity], [Last Modified], [TechSuppRegion], [Technician1], [ExtraDetail])"

dbConnection.Execute strSQLInsert
End Sub
%>
This is called in the edit page based on:
if RetVal = True then

rs.Update
' AfterEdit Event

DoEvent "Call AfterEdit()"

else

rs.CancelUpdate

end if

  • I am assuming this code uses the exiting connection string defined in the other included file xxx_dbconnection.asp
  • This is a test scenario leaving out any parameters thus using "values" instead if "select" "where" - I am assuming this should insert the current record being edited in the xxx_edit page...
    I think I am missing something key as this code does not seem to get called at all...
    Do you have some sample code you could share outlining the use of this cool feature?
    As an aside I could do something similar with VBScript such as initiate an Outlook email message based on the onclick event of the save button but never had any luck calling an ASP "sub" or "function"... So for something like a totals calculation functions would be defined in jsfunctions.js such as:
    function getLabourPartsTotal()

    {

    document.editform.LabourTotal.value = UpdateLabourTotal();

    document.editform.PartsTotal.value = UpdatePartsTotal();

    document.editform.GSTTotal.value = UpdateGSTTotals();

    document.editform.PSTTotal.value = UpdatePSTTotals();

    var var1;

    var var2;

    var var3;

    var var4;

    var1 = UpdateLabourTotal();

    var2 = UpdatePartsTotal();

    var3 = UpdateGSTTotals();

    var4 = UpdatePSTTotals();

    document.editform.Total.value = parseFloat(var1) + parseFloat(var2) + parseFloat(var3) + parseFloat(var4);

    }
    I think this product is amazing just a little confused on a couple issues...

Sergey Kornilov admin 1/19/2006

I recommend you to check Before record updated event where you can choose between several sample actions that deal with both old and new data records.

Sarjent 1/31/2006

This interests me.
For a long time I have wanted to do something similar like the delete function. The idea was to be able to update all selected records with a value.
For instance if you track work order status.

You could select all work orders in a list view and click a button/link that would set "status" to "complete"

C
clig author 11/18/2006

This interests me.

For a long time I have wanted to do something similar like the delete function. The idea was to be able to update all selected records with a value.
For instance if you track work order status.

You could select all work orders in a list view and click a button/link that would set "status" to "complete"


Here you go - what I got working to mimic my SPs in my fat client - take a look at "Before Record Updated" - does what you are looking for. - If you were to apply to all records you'd have to loop an UPDATE until EOF or a WHERE instead of INSERT
edit on load:
Sub EditOnLoad(where)
' Parameters:

' where - string with WHERE clause pointing to record to be edited

'** Custom code ****

' put your custom code here

set CN = server.CreateObject("ADODB.Connection")

CN.Open "DSN=NTSS;UID=sa;PWD=xxxx"

set rs = Server.CreateObject("ADODB.Recordset")

rs.Open "Select LoginName, Name, Email, TSR, Project, ServiceDate, Sims From TSRefUsers Where TSR = " & GetRequestForm("editid"), CN

Session("LoginName") = rs("LoginName")

Session("Name") = rs("Name")

Session("Email") = rs("Email")

Session("TSR") = rs("TSR")

Session("Project") = rs("Project")

Session("ServiceDate") = rs("ServiceDate")

Session("Sims") = rs("Sims")

rs.Close
End Sub

  • This is to establish the email address of the referrer
    Before record updated
    Function BeforeEdit(dict, where)
    ' Parameters:

    ' dict - Scripting.Dictionary object.

    ' Each field on the Edit form represented as 'Field name'-'Field value' pair

    ' where - string with WHERE clause pointing to record to be edited
    dict("Last Modified") = strUserID & " - " & Now()

    dict("CSR") = strUserID

    dict("Status") = "2"

    dict("Resolution Date") = Now()
    '** Save new data in another table ****

    strSQLSave = "INSERT INTO [CSR Records] (Project, Sims, ProblemDescription, Technician, [Tech Support], Priority, Severity, TechSuppRegion, ExtraDetail, SYSType) values ("

    strSQLSave = strSQLSave & "'" & cstr(dict("Project")) & "', '"

    strSQLSave = strSQLSave & cstr(dict("Sims")) & "', '"

    strSQLSave = strSQLSave & "Referral - " & dict("ProblemDescription") & "', "

    strSQLSave = strSQLSave & dict("Technician") & ", '"

    strSQLSave = strSQLSave & dict("CSR") & "', '"

    strSQLSave = strSQLSave & dict("Priority") & "', '"

    strSQLSave = strSQLSave & dict("Severity") & "', '"

    strSQLSave = strSQLSave & dict("TechSuppRegion") & "', '"

    strSQLSave = strSQLSave & dict("ExtraDetail") & "', '"

    strSQLSave = strSQLSave & "Referral"

    strSQLSave = strSQLSave & "')"

    dbConnection.Execute strSQLSave
    BeforeEdit = True
    ' set BeforeEdit to True if you like to proceed with editing this record

    ' set it to False in other case

    End Function
  • this sets any values I need changed in the original referral record and insert the appropriate fields in a new record in another table (ticket queue)
  • "http://www.asprunner.com/forums/index.php?showtopic=3738"; - Discussion on strUserID
    After Record updated - send an email to the referral that the ticket has been taken by an advisor
    Sub AfterEdit()

    '** Send simple email ****

    ' do not forget to setup email parameters like From, SMTP server etc

    ' on 'Security->User login settings' dialog
    email=Session("Email")

    message="A Tech Support Advisor has taken ownership of your referral. You can view and add your own actions to your referral: " & vbcrlf & "http://onapp005/techsupport/ts_new_tickets/CSR_Records_list.asp?TargetPageNumber=1&action=Search&lang=&orderby=&dir=&PageSize=20&masterkey=&SearchField=Sims&SearchOption=Equals&SearchFor="; & Session("Sims")

    subject="Tech Support Referral Ticket Ownership: " & Session("TSR") & " Entered: " & Session("ServiceDate") & " Project: " & Session("Project") & " sims: " & Session("Sims")

    sendmail email, subject, message

    End Sub
  • One piece I left in SQL was a scheduled DTS package that moves any referral records with status = 2 to an archive table - found it easier...
  • Email config was setup in User Login Settings in ASP Runner