Skip to main content

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.

https://stackoverflow.com/questions/29261668/how-to-create-an-ad-hoc-email-and-send-it-using-acumatica


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();
}

 


Reply