Search code examples
c#workday-api

Cannot implicitly convert type 'F_M.Commitment_Ledger_Data__Public_Type' to 'F_M.Commitment_Ledger_Data__Public_Type[]'


I am trying to use the "Put_Ledger" function inside the Financial_management API in Workday, but I keep on getting an error when I try to add the object[] to the object (as it states in the API to do).

Workday has been no help in solving this issue. Here is a sample of the code. The objects are creates, and then added to parent objects:

Ledger_Only_DataType ldOnly = new Ledger_Only_DataType
{
    Actuals_Ledger_ID = "1234567",
    Can_View_Budget_Date = true
};

//Commitment_Ledger_data
Commitment_Ledger_Data__Public_Type cl = new Commitment_Ledger_Data__Public_Type
{
    Commitment_Ledger_Reference = ledgerObject,
    Enable_Commitment_Ledger = true,
    Spend_Transaction_Data = st,
    Payroll_Transaction_Data = pt
};

// This is where the error occurs:
ldOnly.Commitment_Ledger_Data = cl;     

Error message:

"Cannot implicitly convert type 'CallWorkdayAPI.Financial_Management.Commitment_Ledger_Data__Public_Type' to 'CallWorkdayAPI.Financial_Management.Commitment_Ledger_Data__Public_Type[]"


Solution

  • Not familiar with Workday, but I am assuming

    ldOnly.Commitment_Ledger_Data
    

    Is an array of: Commitment_Ledger_Data__Public_Type

    So you need to set it equal to an array of that type, whereas currently you are setting it equal to a single object of that type.

    Ledger_Only_DataType ldOnly = new Ledger_Only_DataType
           {
               Actuals_Ledger_ID = "1234567",
               Can_View_Budget_Date = true
           };
    
           //Commitment_Ledger_data
           Commitment_Ledger_Data__Public_Type cl = new 
             Commitment_Ledger_Data__Public_Type
           {
               Commitment_Ledger_Reference = ledgerObject,
               Enable_Commitment_Ledger = true,
               Spend_Transaction_Data = st,
               Payroll_Transaction_Data = pt
           };
    
           Commitment_Ledger_Data__Public_Type[] cls = new Commitment_Ledger_Data__Public_Type[1];
    
           cls[0] = cl;
    
           ldOnly.Commitment_Ledger_Data = cls;