Skip to main content
Answer

Create new Email Activity for SOOrder, Shipment, Payment and Applications without sending it

  • November 12, 2024
  • 2 replies
  • 66 views

Forum|alt.badge.img

I need to create a new Email Activity for SOOrder, Shipment, and Payment and Applications in my customization code. Was wondering which method I would override for my requirements and what I need to pass into it in order to create this new record. I’m handling emails being sent out with a different provider so I don’t want the emails to be sent out from Acumatica.

Best answer by jmc37

I solved it with the following code:
 

    // Create a new instance of CRActivityMaint to manage activities
CRActivityMaint activityGraph = PXGraph.CreateInstance<CRActivityMaint>();
string body = JsonConvert.SerializeObject(jsonObject, Formatting.Indented);

// Determine the correct RefNoteID based on the entity type
Guid? refNoteID = null;
if (entity is SOOrder order)
{
refNoteID = order.NoteID;
}
else if (entity is SOShipment shipment)
{
refNoteID = shipment.NoteID;
}
else if (entity is ARRegister payment)
{
refNoteID = payment.NoteID;
}

if (refNoteID == null)
{
throw new ArgumentException("Unsupported entity type. Please pass an SOOrder, Shipment, or Payment.");
}

// Create the email activity and populate fields
CRActivity activity = new CRActivity
{
ClassID = CRActivityClass.Email,
Subject = subject,
Body = body,
RefNoteID = refNoteID
};

// Insert and save the email activity
activityGraph.Activities.Insert(activity);
activityGraph.Save.Press();
}

 

2 replies

Patrick Chen
Varsity II
Forum|alt.badge.img+2
  • Varsity II
  • November 13, 2024

Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • Answer
  • November 13, 2024

I solved it with the following code:
 

    // Create a new instance of CRActivityMaint to manage activities
CRActivityMaint activityGraph = PXGraph.CreateInstance<CRActivityMaint>();
string body = JsonConvert.SerializeObject(jsonObject, Formatting.Indented);

// Determine the correct RefNoteID based on the entity type
Guid? refNoteID = null;
if (entity is SOOrder order)
{
refNoteID = order.NoteID;
}
else if (entity is SOShipment shipment)
{
refNoteID = shipment.NoteID;
}
else if (entity is ARRegister payment)
{
refNoteID = payment.NoteID;
}

if (refNoteID == null)
{
throw new ArgumentException("Unsupported entity type. Please pass an SOOrder, Shipment, or Payment.");
}

// Create the email activity and populate fields
CRActivity activity = new CRActivity
{
ClassID = CRActivityClass.Email,
Subject = subject,
Body = body,
RefNoteID = refNoteID
};

// Insert and save the email activity
activityGraph.Activities.Insert(activity);
activityGraph.Save.Press();
}