Skip to main content

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.

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?

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


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


@yuriyzaletskyy69 

The right thing (achieve from UI): 

The wrong thing (achieved through code):

 


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

 

 

 


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


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


@Deetz 

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

tPXProjection(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)]
 

  pSerializable]
  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.

 


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


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


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.


@darylbowman awesome! Thank you for sharing!


Reply