Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

cast Array to class

(0) ShareShare
ReportReport
Posted on by 120 User Group Leader

ServiceLibrary.EltezamServiceRef.SubmitEmployeePayslipInfoRequestStructure   SubmitEmployeePayslipInfoRequestStructure;

ServiceLibrary.EltezamServiceRef.PayslipStructure    PayslipStructure;

SubmitEmployeePayslipInfoRequestStructure   = new ServiceLibrary.EltezamServiceRef.SubmitEmployeePayslipInfoRequestStructure();

PayslipStructure  = new NICServiceLibrary.EltezamServiceRef.PayslipStructure();

PayslipStructure.set_ConsolidationSetID("1");
PayslipStructure.set_ConsolidationSetDescription("Test");
PayslipStructure.set_ElementCode("1004");
PayslipStructure.set_Amount(1200);
PayslipStructure.set_ElementClassification(Paid);

SubmitEmployeePayslipInfoRequestStructure.set_PayslipList(PayslipStructure); // This accepts only array as PayslipStructure()

I have created arrayList class and trying to cast but failed.

I belive the array to created and needs to casted as PayslipStructure().

Please advice

pastedimage1606379686284v1.png

  • Alfasith AX Profile Picture
    120 User Group Leader on at
    RE: cast Array to class

    Thanks Martin for your response.

    1. Hence forth I will represent code as rich formatting view.

    2. I cant use fully C#, the values are from AX, we have to interate this function for all the employees with their list of benefits periodically.

    ServiceLibrary.EltezamServiceRef.PayslipStructure[] payslipStructureArray = new ServiceLibrary.EltezamServiceRef.PayslipStructure[10]();

    They way you represented its works good but Array is looking for size

    Once again Thanks lot.

  • Verified answer
    Martin Dráb Profile Picture
    231,837 Most Valuable Professional on at
    RE: cast Array to class

    Please use Insert > Insert Code (in the rich-formating view) to paste source code. Isn't this better than what you've posted above?

    ServiceLibrary.EltezamServiceRef.SubmitEmployeePayslipInfoRequestStructure submitEmployeePayslipInfoRequestStructure;
    ServiceLibrary.EltezamServiceRef.PayslipStructure payslipStructure;
    
    payslipStructure = new NICServiceLibrary.EltezamServiceRef.PayslipStructure();
    payslipStructure.set_ConsolidationSetID("1");
    payslipStructure.set_ConsolidationSetDescription("Test");
    payslipStructure.set_ElementCode("1004");
    payslipStructure.set_Amount(1200);
    payslipStructure.set_ElementClassification(Paid);
    
    submitEmployeePayslipInfoRequestStructure = new ServiceLibrary.EltezamServiceRef.SubmitEmployeePayslipInfoRequestStructure();
    submitEmployeePayslipInfoRequestStructure.set_PayslipList(payslipStructure); // This accepts only array as PayslipStructure()

    Your code is indeed wrong - you're trying to pass a single payslipStructure to a property that expects an array. Note that it's an array, not the ArrayList class.

    You need code like this:

    ServiceLibrary.EltezamServiceRef.PayslipStructure[] payslipStructureArray = new ServiceLibrary.EltezamServiceRef.PayslipStructure[]();
    payslipStructureArray.SetValue(payslipStructure, 0);
    submitEmployeePayslipInfoRequestStructure.set_PayslipList(payslipStructureArray);

    If I was you, I wouldn't do it in X at all. I would create a C# library (you probably already have one, ServiceLibrary), do most of the stuff there and call this library in X . It can be much simpler in C#. For example:

    using ServiceLibrary.EltezamServiceRef;
    
    PayslipStructure payslip = new PayslipStructure();
    payslip.ConsolidationSetID = "1";
    payslip.ConsolidationSetDescription = "Test";
    payslip.ElementCode = "1004";
    payslip.Amount = 1200;
    payslip.ElementClassification = Paid;
    
    SubmitEmployeePayslipInfoRequestStructure request = new SubmitEmployeePayslipInfoRequestStructure();
    request.PayslipList = new PayslipStructure[] { payslip };
    

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,025 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,837 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans