Skip to main content
Solved

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

  • November 12, 2024
  • 2 replies
  • 28 views

Forum|alt.badge.img
  • Jr Varsity III
  • 10 replies

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

 

View original
Did this topic help you find an answer to your question?

2 replies

Patrick Chen
Jr Varsity III
Forum|alt.badge.img+2
  • Jr Varsity III
  • 51 replies
  • November 13, 2024

Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 10 replies
  • 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();
}

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings