web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

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

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    238,032 Most Valuable Professional on at

    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 };
    

  • Alfasith AX Profile Picture
    120 User Group Leader on at

    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.

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 678 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 394 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 281 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans