Sales Order emailing based on contact position  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Sales Order emailing based on contact position

Postby Atronics » Wed Dec 02, 2015 10:04 am

I need to enhance the emailing based on Contact Positions. The following breakout which uses the spEmailAddress works in V6 but I am struggling to find the relevant event handlers. Can you point me in the right direction for V7
*********************** V6 Breakout
'Form Email Invoice Clicked - Modified By Atronics 07/12/2006
'Last Modified :- 26/09/2011

Dim ReadHandle
Dim SQL

With SalesOrderObject.Database
ReadHandle = .StatementOpen(.ConnectionRead1, False, "", 0)

SQL = "EXEC spEmailAddress '" & SalesOrderObject.DebtorID & "', 'Email Invoice'"
If .ExecuteSelect(CInt(ReadHandle), CStr(SQL)) <> 0 Then
.BindMem CInt(ReadHandle), 1, vbString
If .FetchRow(CInt(ReadHandle)) = True Then
EmailTo = .getData(CInt(ReadHandle), 1)
End If
End If

.StatementRenew CInt(ReadHandle)

If EmailTo = "" Then
MsgBox("No email address on file. Email cancelled")
rtnCancel = True
Else
SQL = "EXEC spEmailAddress '" & SalesOrderObject.DebtorID & "', 'CC Email Invoice'"
If .ExecuteSelect(CInt(ReadHandle), CStr(SQL)) <> 0 Then
.BindMem CInt(ReadHandle), 1, vbString
If .FetchRow(CInt(ReadHandle)) = True Then
CC = .getData(CInt(ReadHandle), 1)
End If
End If

End If

.StatementRenew CInt(ReadHandle)
.StatementClose CInt(ReadHandle)
Subject = "Invoice From Advanced Seed"
NameToGiveAttachment = "Invoice " & SalesOrderObject.InvoiceNo & "-D0" & CStr(SalesOrderObject.SelectedHistoryNo)
Message = "Thank you for your order. Please find our invoice attached" & vbCrLf & vbCrLf & _
"Kind Regards" & vbCrLf & _
SalesOrderObject.Database.JiwaLoginUserName
End With

End Sub

***************************spEmailAddress
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[spEmailAddress]
(@DebtorID char(20),
@Position varchar(50))
AS

Declare @EmailAddress varchar(200)

Select Top 1 @EmailAddress = cc.EmailAddress
From CN_Contact cc, CN_Main cm, CN_ContactPosition cp1
Where cc.ProspectID = cm.ProspectID
And cm.DebtorID = @DebtorID
And cc.PrimaryID = cp1.ContactPositionID
And cp1.Position = @Position

If @EmailAddress Is Null
Select Top 1 @EmailAddress = cc.EmailAddress
From CN_Contact cc, CN_Main cm, CN_ContactPosition cp2
Where cc.ProspectID = cm.ProspectID
And cm.DebtorID = @DebtorID
And cc.SecondaryID = cp2.ContactPositionID
And cp2.Position = @Position

If @EmailAddress Is Null
Select Top 1 @EmailAddress = cc.EmailAddress
From CN_Contact cc, CN_Main cm, CN_ContactPosition cp3
Where cc.ProspectID = cm.ProspectID
And cm.DebtorID = @DebtorID
And cc.TertiaryID = cp3.ContactPositionID
And cp3.Position = @Position

Select EmailAddress = IsNull(@EmailAddress, '')

GO

Atronics

Posts: 21
Joined: Fri Feb 29, 2008 4:40 pm
Atronics
Frequent Contributor
Frequent Contributor
 
Posts: 119
Joined: Fri Feb 29, 2008 4:40 pm
Topics Solved: 10

Re: Sales Order emailing based on contact position  Topic is solved

Postby Mike.Sheen » Sat Dec 05, 2015 2:30 pm

Attached is a fairly complete conversion of what you had in Version 6.

It looks like a lot, but I simply copied the standard "Sales Order - Custom Email" plugin and added the bits to call your stored procedure for the TO and CC recipient address.

Mike
Attachments
Plugin Sales Order Custom Email - Obtain To and CC address from a stored proc.xml
Converted V6 breakouts to V7 Plugin
(34.84 KiB) Downloaded 707 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Sales Order emailing based on contact position

Postby Atronics » Wed Dec 16, 2015 9:30 am

Mike,
Does V7 treat the sp's differently to V6?
When I run the plugin, I get the following error, even though the sp is available.
'spEmailAddress" is not declared. It may be inaccessible due to its protection level.
Attachments
Capture.JPG
Atronics
Frequent Contributor
Frequent Contributor
 
Posts: 119
Joined: Fri Feb 29, 2008 4:40 pm
Topics Solved: 10

Re: Sales Order emailing based on contact position

Postby Mike.Sheen » Wed Dec 16, 2015 9:38 am

Your error is because on line 66 you have:

Code: Select all
Call spEmailAddress


It's thinking you want to invoke a methods named spEmailAddress, and there is none.

The plugin I supplied has that line as:
Code: Select all
' Call spEmailAddress stored proc to obtain TO address   


Note the apostrophe at the start of the line - this indicates it is a comment and the compiler will ignore it. Your line is missing that comment indicator.

Did you modify the plugin I supplied after importing it? If so, undo your changes or re-import the supplied plugin and test again.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 0 guests