Solved

How can I programmatically assign a Related Entity

  • 2 February 2022
  • 12 replies
  • 256 views

Badge +10

I need to programmatically tie an email to a Case. The code I have makes some kind of association, because the email will display in the Case activities. However, the email ‘Related Entity’ field remains blank.

 

Here’s my code:

Base.CurrentMessage.SetValueExt<CRSMEmail.refNoteID>(email, taxCase.NoteID);
email = Base.CurrentMessage.Update(email);
Base.Actions.PressSave();

In the database, the field is being correctly set, but the UI does not reflect the change.

icon

Best answer by darylbowman 25 April 2022, 19:44

View original

12 replies

Userlevel 5
Badge +3

Can you please add few more details:

  1. On which screen you want to have this connection?
  2. For which graph you want to create an extension?
  3. Which action/method you override/extend/append?
Badge +10

@yuriyzaletskyy69 - My more complete code looks like this:

 

public class CREmailActivityMaint_Extension : PXGraphExtension<CREmailActivityMaint>
{
public PXAction<CRSMEmail> AddToTaxCase;
[PXButton(CommitChanges = true, Category = "Actions")]
[PXUIField(DisplayName = "Add To Tax Case")]
protected virtual void addToTaxCase()
{
CRSMEmail email = Base.Message.Current;
if (email is null) return;

CRCase taxCase = BAccountWorkflow.BAccountWorkflow_BusinessAccountMaint_Extension.GetOrCreateCurrentTaxCase(bAccount.BAccountID);
if (taxCase != null)
{
Base.CurrentMessage.SetValueExt<CRSMEmail.refNoteID>(email, taxCase.NoteID);
email = Base.CurrentMessage.Update(email);
Base.Actions.PressSave();
}
}
}

I’ve tried using Base.CurrentMessage and Base.Message. Both assign the correct value. Neither populate the UI field correctly.

Userlevel 5
Badge +3

@Deetz can you add screenshots as well? What do you expect to see in UI field? Why you don’t like what you see in UI field? What should be there instead?

Badge +10

@yuriyzaletskyy69 

The right thing (achieve from UI): 

The wrong thing (achieved through code):

 

Userlevel 7
Badge +17

Hi, @Deetz I just tried with your code but was unable to compile and get the error below. I’m missing something?

 

 

 

Userlevel 5
Badge +3

@Deetz few more questions, which build of Acumatica you use, and which exactly screenid you try to customize?

Badge +10

@yuriyzaletskyy69 - 21.204.0055 and CR.30.60.15

 

@Naveen B - It’s just a method that returns a Case to attach the Activity too. You can write a simple BQL select to get a Case.

Userlevel 5
Badge +3

@Deetz 

I’m looking on  CRSMEmail declaration, and see that it is a PXProjection : 

[PXProjection(typeof (Select2<CRActivity, InnerJoin<SMEmail, On<SMEmail.refNoteID, Equal<CRActivity.noteID>>>, Where<CRActivity.classID, Equal<CRActivityClass.email>, Or<CRActivity.classID, Equal<CRActivityClass.emailRouting>>>>), Persistent = true)]
 

  [Serializable]
  public class CRSMEmail : CRActivity

If to look on declaration of RefNoteID, we see following:

[PXDBGuid(false, BqlField = typeof (CRActivity.refNoteID))]

…………………...

[PXUIField(DisplayName = "References Nbr.")]

 public override Guid? RefNoteID { get; set; }

 

If to sum up, in order for your entity to work, it must satisfy following criteria:

  1. is should correspond to PXProjection requirements, which states that NoteID should have record in SMEmail, classID should be equal to email or class id equal to email routing
  2. It should live in table CRActivity

Without 1 and 2 satisfied, Acumatica will either crash, or behave in a strange way.

 

Badge +10

@yuriyzaletskyy69  I’m not sure I’m following. It sounds like those requirements would be for creating a new CRSMEmail, which is not what I’m doing. I’m simply trying to add the CRSMEmail to a Case via the RefNoteID. This works in the backend, as it shows up under the Case’s Activity tab, but the CRSMEmail ‘Related Entity’ field doesn’t give the entity description like it’s supposed to. This is a calculated field on CRActivity (PXFormula). I’m not sure how to accomplish  this.

Userlevel 7
Badge

Hi @darylbowman were you ever able to resolve your issue? Thank you!

Badge +10

I was actually.

 

 

Here’s my code:

Guid? noteID = PXNoteAttribute.GetNoteID<CRCase.noteID>(caseGraph.Case.Cache, taxCase);
caseGraph.Case.Update(taxCase);
caseGraph.Actions.PressSave();

// Reassign Appointment to Case instead, so the Case's 'Appointment Date' is correct
bAccountGraph.Activities.Current = bAccountGraph.Activities.Search<CRPMTimeActivity.noteID>(appointment.NoteID);
bAccountGraph.Activities.SetValueExt<CRPMTimeActivity.refNoteID>(appointment, taxCase.NoteID);
bAccountGraph.Activities.Update(appointment);
bAccountGraph.Actions.PressSave();

If I remember correctly, 

Guid? noteID = PXNoteAttribute.GetNoteID<CRCase.noteID>(caseGraph.Case.Cache, taxCase);

performs an insert on the Note table which allows the association to occur.

Userlevel 7
Badge

@darylbowman awesome! Thank you for sharing!

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 — 2024  Acumatica, Inc. All rights reserved