2017-04-25 48 views
0

我試圖創建一個動作一個僱員。在UI如何建立員工與行動

我已經確定了最低要求的領域: - 僱員(鍵字段) - 姓氏(聯繫DAC) - Employee類 - 部門

我最初試圖進入這些值只期待SetValueExt將運行默認事件並分配其他請求的字段,但運行該操作後,我得到了不同的消息,請求這些附加字段。所以我也包括他們。

我的代碼是尋找如下:

 public PXAction<EPEmployee> testAction; 
    [PXButton] 
    [PXUIField(DisplayName = "EXTENDED")] 
    protected virtual IEnumerable TestAction(PXAdapter adapter) 
    { 
     EmployeeMaint employeeMaintGraph = PXGraph.CreateInstance<EmployeeMaint>(); 
     employeeMaintGraph.Clear(); 


     EPEmployee epEmployeeRow = new EPEmployee(); 
     epEmployeeRow.AcctCD = "CODED"; 
     epEmployeeRow.AcctName = "employee"; 
     epEmployeeRow.Status = "A"; 
     employeeMaintGraph.Employee.Insert(epEmployeeRow); 

     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.vendorClassID>(epEmployeeRow, "EMPDEFAULT"); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.classID>(epEmployeeRow, "EMPDEFAULT"); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.departmentID>(epEmployeeRow, "ADMIN"); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.positionLineCntr>(epEmployeeRow, 1); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.consolidateToParent>(epEmployeeRow, false); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.allowOverrideCury>(epEmployeeRow, true); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.allowOverrideRate>(epEmployeeRow, false); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.payToParent>(epEmployeeRow, false); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.acctName>(epEmployeeRow, "employee"); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.vendor1099>(epEmployeeRow, false); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.taxAgency>(epEmployeeRow, false); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.updClosedTaxPeriods>(epEmployeeRow, false); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.taxReportRounding>(epEmployeeRow, "R"); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.taxUseVendorCurPrecision>(epEmployeeRow, true); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.taxReportFinPeriod>(epEmployeeRow, false); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.taxPeriodType>(epEmployeeRow, "M"); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.enableTaxStartDate>(epEmployeeRow, false); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.landedCostVendor>(epEmployeeRow, false); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.isLaborUnion>(epEmployeeRow, false); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.lineDiscountTarget>(epEmployeeRow, "E"); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.ignoreConfiguredDiscounts>(epEmployeeRow, false); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.sVATReversalMethod>(epEmployeeRow, "D"); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.sVATInputTaxEntryRefNbr>(epEmployeeRow, "M"); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.sVATOutputTaxEntryRefNbr>(epEmployeeRow, "M"); 
     employeeMaintGraph.CurrentEmployee.Cache.SetValueExt<EPEmployee.type>(epEmployeeRow, "EP"); 

     employeeMaintGraph.CurrentEmployee.Update(epEmployeeRow); 

     Contact contactRow = new Contact(); 
     contactRow.LastName = "lastname"; 
     employeeMaintGraph.Contact.Insert(contactRow); 


     Address addressRow = new Address(); 
     addressRow.CountryID = "US"; 
     employeeMaintGraph.Address.Insert(addressRow); 


     employeeMaintGraph.Actions.PressSave(); 

     return adapter.Get();} 

有了這個最新版本我得到的消息: 「錯誤:‘科’不能爲空錯誤:。‘默認位置’不能爲空錯誤:'路由電子郵件'不能爲空

我已經在BAccount,Employee,Vendor(員工DAC繼承它),聯繫人和地址表中找到了數據庫中的Branch字段,但沒有運氣。 任何想法可能是什麼錯誤?

謝謝。

回答

1

請參考下面的代碼段的示例創建操作內的僱員:

public PXAction<EPEmployee> CreateEmployee; 
[PXButton] 
[PXUIField(DisplayName = "Create Employee")] 
protected void createEmployee() 
{ 
    EmployeeMaint employeeMaintGraph = PXGraph.CreateInstance<EmployeeMaint>(); 
    EPEmployee epEmployeeRow = new EPEmployee(); 
    epEmployeeRow.AcctCD = "EMPLOYEE1"; 
    epEmployeeRow = employeeMaintGraph.Employee.Insert(epEmployeeRow); 

    Contact contactRow = employeeMaintGraph.Contact.Current = employeeMaintGraph.Contact.Select(); 
    contactRow.FirstName = "John"; 
    contactRow.LastName = "Green"; 
    employeeMaintGraph.Contact.Update(contactRow); 

    Address addressRow = employeeMaintGraph.Address.Current = employeeMaintGraph.Address.Select(); 
    addressRow.CountryID = "US"; 
    addressRow = employeeMaintGraph.Address.Update(addressRow); 
    addressRow.State = "DC"; 
    employeeMaintGraph.Address.Update(addressRow); 

    epEmployeeRow.VendorClassID = "EMPSTAND"; 
    epEmployeeRow.DepartmentID = "FINANCE"; 
    employeeMaintGraph.Employee.Update(epEmployeeRow); 

    employeeMaintGraph.Actions.PressSave(); 

    throw new PXRedirectRequiredException(employeeMaintGraph, null); 
} 
+0

由於魯斯蘭。我會給它一個鏡頭 –

+0

謝謝@RuslanDev。工作很好。我看到了我的錯誤。 1跟進的問題:你分配** employeeMaintGraph.Contact.Current = employeeMaintGraph.Contact.Select(); **爲特定的原因是什麼? 調試之後,似乎該數據視圖的內容在初始插入後已經可用。 我試圖像這樣**聯繫contactRow = employeeMaintGraph.Contact.Current **,似乎正確保存記錄 –

+0

當插入一個新員工,'employeeMaintGraph.Contact.Current'將始終返回主聯繫人記錄作爲接觸記錄會自動插入緩存,因此可通過PXCache/Data View的Current屬性變爲可用。 「Select()」方法的使用更通用一些,因爲它可以在所有可能的情況下工作,無論您是需要插入新的Employee還是更新現有的Employee。 – RuslanDev