Skip to main content
Solved

How can I programmatically assign a Related Entity

  • Feb 2, 2022 5:55 PM UTC
  • 12 replies
  • 428 views
  • Translate All

darylbowman
Captain II
Forum|alt.badge.img+17

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.

Best answer by darylbowman

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.

View original

12 replies

Yuriy Zaletskyy
Jr Varsity II
Forum|alt.badge.img+4

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?
Translate

darylbowman
Captain II
Forum|alt.badge.img+17

@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.

Translate

Yuriy Zaletskyy
Jr Varsity II
Forum|alt.badge.img+4

@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?

Translate

darylbowman
Captain II
Forum|alt.badge.img+17

@yuriyzaletskyy69 

The right thing (achieve from UI): 

The wrong thing (achieved through code):

 

Translate

Naveen Boga
Captain II
Forum|alt.badge.img+20
  • Captain II
  • Feb 2, 2022 10:19 PM UTC

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

 

 

 

Translate

Yuriy Zaletskyy
Jr Varsity II
Forum|alt.badge.img+4

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

Translate

darylbowman
Captain II
Forum|alt.badge.img+17

@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.

Translate

Yuriy Zaletskyy
Jr Varsity II
Forum|alt.badge.img+4

@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.

 

Translate

darylbowman
Captain II
Forum|alt.badge.img+17

@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.

Translate

Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • Apr 25, 2022 5:31 PM UTC

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

Translate

darylbowman
Captain II
Forum|alt.badge.img+17
  • Author
  • Answer
  • Apr 25, 2022 5:44 PM UTC

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.

Translate

Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • Apr 25, 2022 7:36 PM UTC

@darylbowman awesome! Thank you for sharing!

Translate