protected virtual void PMSubTask_Position_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            PMSubTask pmSubTaskRow = (PMSubTask)e.Row;

            PMSubTask subTasksSet = PXSelect <PMSubTask,
                                              Where <PMSubTask.projectID, Equal <Required <PMSubTask.projectID> >,
                                                     And <PMSubTask.taskID, Equal <Required <PMSubTask.taskID> > > >,
                                              OrderBy <Desc <PMSubTask.position> > >
                                    .SelectWindowed(this.Base, 0, 1, pmSubTaskRow.ProjectID, pmSubTaskRow.TaskID);

            if (subTasksSet != null &&
                subTasksSet.Position > 0)
            {
                pmSubTaskRow.Position = subTasksSet.Position + 1;
            }
            else
            {
                pmSubTaskRow.Position = 1;
            }
        }
        /// <summary>
        /// Adds subtasks to the Smartsheet project
        /// </summary>
        /// <param name="smartsheetClient"></param>
        /// <param name="columnMap"></param>
        /// <param name="sheet"></param>
        /// <param name="taskRow"></param>
        /// <param name="pmTemplateTaskSSExtRow"></param>
        /// <param name="subTaskRow"></param>
        /// <param name="columnID"></param>
        /// <param name="dependencyStartDateOffset"></param>
        /// <param name="dependencySibling"></param>
        /// <returns></returns>
        public long AddSubTasks(SmartsheetClient smartsheetClient,
                                Dictionary <string, long> columnMap,
                                Sheet sheet, PMTask taskRow,
                                PMTaskSSExt pmTemplateTaskSSExtRow,
                                PMSubTask subTaskRow,
                                long?columnID,
                                int dependencyStartDateOffset,
                                long dependencySibling)
        {
            List <Cell> newCells = new List <Cell>();

            Cell currentCell = new Cell.AddCellBuilder(columnMap[SmartsheetConstants.GanttTemplateMapping.TASK_NAME], subTaskRow.SubTaskCD).Build();

            currentCell.Format = SmartsheetConstants.CellFormat.LARGE_GRAY_BACKGROUND;
            newCells.Add(currentCell);

            if (pmTemplateTaskSSExtRow.UsrEnableSubtaskDependency == true)
            {
                DateTime adjustedStartDate = taskRow.StartDate.Value.AddDays((double)dependencyStartDateOffset);
                currentCell = new Cell.AddCellBuilder(columnMap[SmartsheetConstants.GanttTemplateMapping.START], adjustedStartDate).Build();
                newCells.Add(currentCell);
            }
            else
            {
                currentCell = new Cell.AddCellBuilder(columnMap[SmartsheetConstants.GanttTemplateMapping.START], taskRow.StartDate).Build();
                newCells.Add(currentCell);
            }

            currentCell = new Cell.AddCellBuilder(columnMap[SmartsheetConstants.GanttTemplateMapping.DURATION], subTaskRow.Duration.ToString()).Build();
            newCells.Add(currentCell);
            currentCell = new Cell.AddCellBuilder(columnMap[SmartsheetConstants.GanttTemplateMapping.COMMENTS], subTaskRow.Description).Build();
            newCells.Add(currentCell);

            Row currentRow = new Row.AddRowBuilder(null, true, null, null, null).SetCells(newCells).Build();

            currentRow.ParentId = (long)columnID;

            currentRow.Format = SmartsheetConstants.CellFormat.GRAY_BACKGROUND;

            List <Row> newSSRows = new List <Row>();

            newSSRows.Add(currentRow);

            IList <Row> ssRows = smartsheetClient.SheetResources.RowResources.AddRows((long)sheet.Id, newSSRows);

            return((long)ssRows[0].Id);
        }
        protected virtual void buttonUp()
        {
            PMSubTask currentSubTaskRow = SelectedSubTasks.Current;

            PMSubTask prevSubTask = PXSelect <PMSubTask,
                                              Where <PMSubTask.projectID, Equal <Required <PMSubTask.projectID> >,
                                                     And <PMSubTask.taskID, Equal <Required <PMSubTask.taskID> >,
                                                          And <PMSubTask.position, Less <Required <PMSubTask.position> > > > >,
                                              OrderBy <Desc <PMSubTask.position> > >
                                    .SelectWindowed(this.Base, 0, 1, currentSubTaskRow.ProjectID, currentSubTaskRow.TaskID, currentSubTaskRow.Position);

            if (prevSubTask != null)
            {
                int swapPosition = (int)prevSubTask.Position;
                prevSubTask.Position       = currentSubTaskRow.Position;
                currentSubTaskRow.Position = swapPosition;

                this.SelectedSubTasks.Update(currentSubTaskRow);
                this.SelectedSubTasks.Update(prevSubTask);
            }

            this.Base.Actions.PressSave();
        }