Email sales order without attachment

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

Email sales order without attachment

Postby DannyC » Fri Jan 14, 2022 11:02 am

If a certain scenario is met during sales order entry and/or saving I want to send an email. No need for any attachment. It's just an in-house email to another department with relevant subject & body.

Is it possible to use
Code: Select all
salesOrder.Email
?

I have tried and it seems to require SalesOrderReport, nameToGiveAttachment et al. I really just need to populate EmailTo, EmailFrom, Subject, Body.
The other option might be to create an EmailLog and just use
Code: Select all
SalesOrder.EmailLogCollection.Add(emailLog)

but I'm having trouble creating an email log item via
Code: Select all
JiwaFinancials.Jiwa.JiwaSales.SalesOrder.EmailLog emailLog = Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.EmailLog>(null);

The above line generates an error "No overload for method 'CreateCollectionItem' takes 1 arguments.

What do you suggest might be the best way to generate an email - ensuring it is reflected in the email log/shows in the emailed badge?
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Email sales order without attachment

Postby SBarnes » Fri Jan 14, 2022 2:47 pm

There is a business object JiwaFinancials.Jiwa.JiwaApplication.JiwaEmail.EmailMessage.EmailMessage, that is just a business object instantiate with the factory on the manager, set the necessary properties and save it and it will send the email using Jiwa's email system. You would then have to write to the log yourself though.

If you didn't want to send an email you could also send a To do also which would avoid the log entirely.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Email sales order without attachment

Postby DannyC » Fri Jan 14, 2022 4:18 pm

You would then have to write to the log yourself though
.
Yep, I know about EmailMessage already, but the issue is writing to the log.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Email sales order without attachment

Postby pricerc » Mon Jan 17, 2022 4:02 pm

I have this bit of code which might help get you going:

Code: Select all
            Try
                Dim email = salesOrder.Manager.BusinessLogicFactory.CreateBusinessLogic(Of JiwaEmail.EmailMessage)(Nothing)
                email.Setup()

                With email
                    .CreateNew()
                    .EmailFrom = message.EmailFrom
                    .EmailTo = message.EmailTo
                    .EmailCC = message.EmailCC
                    .EmailBCC = message.EmailBCC
                    .EmailSubject = message.EmailSubject
                    .BodyIsHTML = message.EmailBody.EndsWith("</html>", StringComparison.OrdinalIgnoreCase)
                    .EmailBody = message.EmailBody
                    .SourceForm = "JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm"
                    .SourceDisplayNo = salesOrder.InvoiceNo
                    .SourceType = "Sales Order"
                    .SourceID = salesOrder.RecID

                    If attachments IsNot Nothing Then
                        For Each a In attachments
                            .Attachments.Add(a)
                        Next
                    End If
                    .Status = JiwaEmail.EmailMessage.EmailStatuses.Sent

                    ' this will actually send the message, if the 'new' status is 'Sent'.
                    .Save()
                End With

                Dim mailLog As New JiwaSales.SalesOrder.EmailLog() With {
                    .From = email.EmailFrom,
                    .EmailTo = email.EmailTo,
                    .BCC = email.EmailBCC,
                    .CC = email.EmailCC,
                    .Subject = email.EmailSubject,
                    .Body = email.EmailBody,
                    .EmailDateTime = email.DateSent,
                    .InvoiceID = salesOrder.RecID,
                    .InvoiceHistoryID = snapshot.RecID,
                    .EM_Main_RecID = email.RecID
                }

                salesOrder.EmailLogCollection.Add(mailLog)
                salesOrder.InvoiceEmailed = True
                snapshot.InvoiceEmailed = True
                salesOrder.Save()
                salesOrder.Read(salesOrder.RecID)
                Return True
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                Debug.Print(ex.ToString())
                If Debugger.IsAttached Then Debugger.Break()
                Return False
            End Try

/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 518
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 21


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 5 guests