1
votes

I have a strange issue. I'm trying to add a task related to a lead. I wrote the following code and it works fine and appears under the lead under activities. However, when I browse the tasks, the "Related Entity Description" field is blank. I looked at the code behind it and it appears related entity description should be automatically calculated from the RefNoteId in Acumatica 6. If I manually create an item under the lead/activity then all other lead/activities update the "related entity description" properly. Looking at the source, it appears this field is myTask.Source which is a string value and I'm not sure what it should be set to since it should be calculated automatically with the noteid. I looked in the SQL database and all fields from a manually created task and my automatic created task including the NoteID are correct so it appears I'm missing some sort of "update" command. Any insight what I am missing to get the "Related Entity Description" to calculate correctly? Thanks.

private void followuphelper(int daysToFollowUp)
        {
            #region Event Handlers
            Contact curLead = Base.LeadCurrent.SelectSingle();
            CRTaskMaint graph = CRTaskMaint.CreateInstance<CRTaskMaint>();

            CRActivity myTask = new CRActivity();
            myTask.Subject = String.Format("FollowUp Lead");
            myTask.ClassID = 0;
            DateTime dueDate = DateTime.Now;
            myTask.StartDate = dueDate;
            myTask.EndDate = dueDate.AddDays(daysToFollowUp); //2 weeks

            myTask.RefNoteID = curLead.NoteID; 
            myTask.ContactID = curLead.ContactID; 

            CRActivity task = (CRActivity)graph.Tasks.Insert(myTask);

            Base.Actions.PressSave();
            graph.Actions.PressSave();
}
1

1 Answers

1
votes

I just verified below code and it does show up Related Entity:

public class LeadMaintPXExt : PXGraphExtension<LeadMaint>
{
    public PXAction<Contact> FollowUpTask;
    [PXUIField(DisplayName = "FollowUp Task")]
    [PXButton()]
    private void followUpTask()
    {
        CRTaskMaint graph = PXGraph.CreateInstance<CRTaskMaint>();

        CRActivity myTask = new CRActivity();
        myTask.Subject = String.Format("FollowUp Lead Test");
        myTask.ClassID = 0;
        DateTime dueDate = DateTime.Now;
        myTask.StartDate = dueDate;
        myTask.EndDate = dueDate.AddDays(10);

        myTask.RefNoteID = Base.Lead.Current.NoteID;
        myTask.ContactID = Base.Lead.Current.ContactID;

        CRActivity task = (CRActivity)graph.Tasks.Insert(myTask);

        graph.Actions.PressSave();
    }
}

enter image description here

Related Entity Description is looking for a matching NoteID record in Note table. This record gets created on-demand, when needed. For New Lead, if you wish you continue with above code, then you need to request Note creation by calling GetNoteID for PXNoteAttribute and persist the record.

Example:

PXNoteAttribute.GetNoteID<Contact.noteID>(Base.Lead.Cache, Base.Lead.Current);
Base.Actions.PressSave();

Out-of-box Activity actions (Add Task, Add Event Etc), takes care of this internally. If you use below approach, all initialization is done internally.

public class LeadMaintPXExt : PXGraphExtension<LeadMaint>
{
    public PXAction<Contact> FollowUpTask;
    [PXUIField(DisplayName = "FollowUp Task")]
    [PXButton()]
    private void followUpTask()
    {
        try
        {
            //out-of-box Activities -> "New Task" Action
            Base.Actions["NewTask"].Press();
        }
        catch (Exception ex)
        {
            if (ex is PXRedirectRequiredException)
            {
                CRTaskMaint graph = (ex as PXRedirectRequiredException).Graph as CRTaskMaint;
                if (graph != null)
                {
                    CRActivity myTask = graph.Tasks.Current;
                    myTask.Subject = String.Format("FollowUp Lead Test");
                    myTask.ClassID = 0;
                    DateTime dueDate = DateTime.Now;
                    myTask.StartDate = dueDate;
                    myTask.EndDate = dueDate.AddDays(10);

                    CRActivity task = graph.Tasks.Update(myTask);

                    graph.Actions.PressSave();
                }
            }
        }
    }
}