Skip to main content
Solved

Row insertion to a Tab Based on Status change with some parameters.


Forum|alt.badge.img

In Projects screen (PM301000) When I click the Status changed to Active State (By clicking the Activate Project the status Change to active from In planning) , I need to Create a Task (CR306020) in the activities tab add added as a row to it. also I need to pass some parameters from summary tab to  task form. like;
PMProject.ContractCD = CRActivity.Subject
PMProject.StartDate =CRActivity.StartDate_Date
PMProject.OwnerID = CRActivity.OwnerID
below is the error I'm getting and the code 
any help to resolve this 

sss

 

using PX.Api;
using PX.Data;
using PX.Data.DependencyInjection;
using PX.LicensePolicy;
using PX.Objects.AP;
using PX.Objects.AR;
using PX.Objects.CA;
using PX.Objects.CM.Extensions;
using PX.Objects.Common;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.CT;
using PX.Objects.EP;
using PX.Objects.Extensions.MultiCurrency;
using PX.Objects.GL;
using PX.Objects.GL.FinPeriods;
using PX.Objects.IN;
using PX.SM;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using PX.Data.BQL.Fluent;
using PX.Data.BQL;
using PX.Common;
using PX.Objects.PO;
using PX.Objects.SO;
using PX.Objects.CR.Extensions;
using PX.Api.ContractBased.UI;
using PX.Objects;
using PX.Objects.PM;
using static PX.Objects.CT.Contract;

namespace PX.Objects.PM
{
    public class ProjectEntry_Extension : PXGraphExtension<PX.Objects.PM.ProjectEntry>
    {
        protected void PMProject_Status_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            var row = (PMProject)e.Row;
            if (row != null && row.Status == ProjectStatus.Active)
            {
                // Acuminator disable once PX1043 SavingChangesInEventHandlers [Justification]
                CreateTask(row);
            }
        }

        private void CreateTask(PMProject project)
        {
            // Create a new task
            CRActivity task = new CRActivity
            {
                // ClassID = CRActivityClass.Task, // Ensure the ClassID is set correctly
                Subject = $"{project.ContractCD.Trim()} - {project.Description.Trim()}",
                StartDate = project.StartDate,
                // UIStatus = ActivityStatusListAttribute.Open.Trim(),
                OwnerID = project.OwnerID
            };

            // Insert the task
            PXCache taskCache = Base.Caches[typeof(CRActivity)];
            task = (CRActivity)taskCache.Insert(task);
            taskCache.Persist(PXDBOperation.Insert);
        }
    }
}

 

Best answer by rashmikamudalinayake10

Couldn’t able to change, tried another way and sorted out.

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

4 replies

Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

Hi @rashmikamudalinayake10,

I don’t think it would be a good idea to use the FieldUpdated to perform the task. From the code, I understand you would like to create Task when the Project is being Activated. If that’s the case, you can override the Activate action to create the Tasks then you call the base. Below is an example code you can try,

    public class ProjectEntry_Extension : PXGraphExtension<PX.Objects.PM.ProjectEntry>
    {
        #region Event Handlers
        public delegate IEnumerable ActivateDelegate(PXAdapter adapter);
        [PXOverride]
        public IEnumerable Activate(PXAdapter adapter, ActivateDelegate baseMethod)
        {
            CreateTask((PMProject)Base.Project.Current);
            return baseMethod(adapter);
        }
        #endregion
        private void CreateTask(PMProject project)
        {
            var taskGraph = PXGraph.CreateInstance<CRTaskMaint>();
            var activity = taskGraph.Tasks.Cache.InitNewRow<CRActivity>();
            activity.Subject = "From Graph Method";
            taskGraph.Tasks.Cache.Insert(activity);
            taskGraph.Persist();
        }
    }

Hope that helps, feel free to post back if you have any questions.

Happy Coding.!


Forum|alt.badge.img
using PX.Api;
using PX.Data;
using PX.Data.DependencyInjection;
using PX.LicensePolicy;
using PX.Objects.AP;
using PX.Objects.AR;
using PX.Objects.CA;
using PX.Objects.CM.Extensions;
using PX.Objects.Common;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.CT;
using PX.Objects.EP;
using PX.Objects.Extensions.MultiCurrency;
using PX.Objects.GL;
using PX.Objects.GL.FinPeriods;
using PX.Objects.IN;
using PX.SM;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using PX.Data.BQL.Fluent;
using PX.Data.BQL;
using PX.Common;
using PX.Objects.PO;
using PX.Objects.SO;
using PX.Objects.CR.Extensions;
using PX.Api.ContractBased.UI;
using PX.Objects;
using PX.Objects.PM;

namespace PX.Objects.PM
{
	public class ProjectEntry_Extension : PXGraphExtension<PX.Objects.PM.ProjectEntry>
	{
        #region Event Handlers
        public delegate IEnumerable ActivateDelegate(PXAdapter adapter);

        [PXOverride]
        public IEnumerable Activate(PXAdapter adapter, ActivateDelegate baseMethod)
        {
            CreateTask((PMProject)Base.Project.Current);
            return baseMethod(adapter);
        }

        private void CreateTask(PMProject project)
        {
            var customer = PXSelect<Customer,
                            Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>
                            .Select(Base, project.CustomerID); 

            if (customer == null) return;

            var taskGraph = PXGraph.CreateInstance<CRTaskMaint>();
            var activity = taskGraph.Tasks.Cache.CreateInstance() as CRActivity;
            string customerCD = ((Customer)customer).AcctCD;

            activity.Subject = $"{customerCD} - {project.Description.Trim()}";
            activity.StartDate = project.StartDate;

            var contract = PXSelect<Contract,
                            Where<Contract.contractID, Equal<Required<Contract.contractID>>>>
                            .Select(Base, project.ContractID);

            //var contractExt = PXCache<Contract>.GetExtension<ContractExt>(contract);
            //activity.EndDate = contractExt?.UsrMeasuredonDate;
            activity.OwnerID = project.OwnerID;

            taskGraph.Tasks.Insert(activity);
            taskGraph.Persist();

            // get the first task of the project
            var projectTaskResult = PXSelect<PMTask,
                Where<PMTask.projectID, Equal<Required<PMTask.projectID>>>>
                .Select(Base, project.ContractID).First();

            if (projectTaskResult == null) return;

            PMTask projectTask = projectTaskResult;

            //  managing PMTimeActivity
            var timeActivityGraph = PXGraph.CreateInstance<TimeCardMaint>();
            var timeActivityCache = timeActivityGraph.Caches<PMTimeActivity>();
            var timeActivity = timeActivityCache.CreateInstance() as PMTimeActivity;


            timeActivity.ProjectID = project.ContractID;  // Set ProjectID to ContractID
            timeActivity.ProjectTaskID = projectTask.TaskID;  // Set ProjectTaskID

            timeActivityCache.Insert(timeActivity);
            timeActivityGraph.Actions.PressSave();
        }

        private void InsertActivityIntoProject(CRActivity activity, PMProject project)
        {
            if (activity == null) return;

            PMTask projectTask = PXSelect<PMTask, Where<PMTask.projectID, Equal<Required<PMTask.projectID>>>>
                                .Select(Base, project.ContractID)
                                .FirstOrDefault();

            int? projectTaskID = projectTask?.TaskID;

            PMCRActivity pmActivity = new PMCRActivity
            {
                RefNoteID = activity.NoteID,
                ProjectID = Base.Project.Current.ContractID,
                StartDate = activity.StartDate,
                Subject = activity.Subject,
                OwnerID = activity.OwnerID,
                Summary = activity.Subject,
                ProjectTaskID = projectTaskID
            };

            Base.Caches[typeof(PMCRActivity)].Insert(pmActivity);
            Base.Actions.PressSave();
        }
        #endregion
    }
}

In here,


1. I couldn’t set PMTimeActivity.ProjectID  and PMTimeActivity.ProjectTaskID

2. When i create a new row in activities tab the summary  redirects to 

cr306010 but it should be redirected to cr306020 screen 

What did i missed here?

 


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2622 replies
  • July 2, 2024

Hi @rashmikamudalinayake10 were you able to find a solution? Thank you!


Forum|alt.badge.img

Couldn’t able to change, tried another way and sorted out.


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