Solved

Email signature in Events

  • 23 November 2021
  • 3 replies
  • 60 views

Hello:

I have a requirement to generate a “signature” in the body of an Event in Acumatica as a default when creating a new Event.  There does not appear to be an option to select the “source” for an Event, so I am attempting to code it.  I have been able to get the currently logged in users name and set it using the below code:

namespace PX.Objects.EP
{
  public class EPEventMaint_Extension : PXGraphExtension<EPEventMaint>
  {
    #region Event Handlers
    protected void CRActivity_Body_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
    {
      //var row = (CRActivity)e.Row;
      var userId= PXAccess.GetUserID();
      var displayName = PXAccess.GetUserDisplayName();
      e.NewValue = "<br /><b>Name:" + displayName + "</b><br /><b>Phone:</b><br /><b>URL:</b>";
    }
    #endregion
  }
 };

However, I am also needing to get the currently logged in employee’s Business 1 phone number and Web address to complete.  I imagine this would be some sort of BQL search using the PXAccess.GetUserID() value to walk the EPEmployee table and the BAccount table, but I dont know how to code this.  It seems to me that there might be some inbuilt function for collecting currently logged in users’ employee values, but I cant seem to find anything out there on this.  Can anyone provide an assist?  Thanks in advance!

 

 

icon

Best answer by jinin 23 November 2021, 09:59

View original

3 replies

Userlevel 3
Badge +1

Hi @scalhoon40,

 

please try with the below BQL,

 var userId = ServiceLocator.Current.GetInstance<ICurrentUserInformationProvider>().GetUserId();   // PXAccess.GetUserID();

           PXResult<EPEmployee,BAccount,Contact> result = (PXResult<EPEmployee, BAccount, Contact>)PXSelectJoin<EPEmployee,
                                        InnerJoin<BAccount, On<EPEmployee.bAccountID, Equal<BAccount.bAccountID>>,
                                        InnerJoin<Contact, On<Contact.contactID, Equal<BAccount.defContactID>>>>,
                                        Where<EPEmployee.userID, Equal<Required<EPEmployee.userID>>>>.Select(Base, userId);

            Contact objContact = result;

            string Phone1 = objContact.Phone1;
            string website = objContact.WebSite;

jinin:

 

Thank you so very much for the reply!  This worked with one exception; when using 

var userId = ServiceLocator.Current.GetInstance<ICurrentUserInformationProvider>().GetUserId();

when I publish, it generates an error:

error CS0103: The name 'ServiceLocator' does not exist in the current context

So, I switched to 

var userId = PXAccess.GetUserID();


and it worked perfectly.  Thank you again for your help on this one and hopefully someone else can get value out of this!

Userlevel 3
Badge +1

Hi @scalhoon40 

We need to add the namespace “CommonServiceLocator” to use the ServiceLocator.

 

Thanks for your update.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2020  Acumatica, Inc. All rights reserved