Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Iterate .net array of objects in X++

(0) ShareShare
ReportReport
Posted on by

Hi Martin,

I have CLR object of the following type

public partial class Response_Create_CustomerContact {

private string customerAccountD365Field;

private string sourceField;

private string customerNoNAVField;

private bool errorField;

private string errortextField;

/// <remarks/>
public string CustomerAccountD365 {
get {
return this.customerAccountD365Field;
}
set {
this.customerAccountD365Field = value;
}
}

/// <remarks/>
public string source {
get {
return this.sourceField;
}
set {
this.sourceField = value;
}
}

/// <remarks/>
public string CustomerNoNAV {
get {
return this.customerNoNAVField;
}
set {
this.customerNoNAVField = value;
}
}

/// <remarks/>
public bool Error {
get {
return this.errorField;
}
set {
this.errorField = value;
}
}

/// <remarks/>
public string Errortext {
get {
return this.errortextField;
}
set {
this.errortextField = value;
}
}
}

i'm getting array of type  Response_Create_CustomerContact as a response 

I'm not sure that how can i iterate in order to read the values in x++

  • Suggested answer
    Martin Dráb Profile Picture
    231,833 Most Valuable Professional on at
    RE: Iterate .net array of objects in X++

    Please always use Insert > Insert Code (in the rich formatting view) to paste source code. Isn't the following much nicer than what you posted?

    public partial class Response_Create_CustomerContact
    {
    	private string customerAccountD365Field;
    	private string sourceField;
    	private string customerNoNAVField;
    	private bool errorField;
    	private string errortextField;
    	
    	/// 
    	public string CustomerAccountD365
    	{
    		get
    		{
    			return this.customerAccountD365Field;
    		}
    		set
    		{
    			this.customerAccountD365Field = value;
    		}
    	}
    	
    	/// 
    	public string source
    	{
    		get
    		{
    			return this.sourceField;
    		}
    		set
    		{
    			this.sourceField = value;
    		}
    	}
    	
    	/// 
    	public string CustomerNoNAV
    	{
    		get
    		{
    			return this.customerNoNAVField;
    		}
    		set
    		{
    			this.customerNoNAVField = value;
    		}
    	}
    	
    	/// 
    	public bool Error
    	{
    		get
    		{
    			return this.errorField;
    		}
    		set
    		{
    			this.errorField = value;
    		}
    	}
    	
    	/// 
    	public string Errortext
    	{
    		get
    		{
    			return this.errortextField;
    		}
    		set
    		{
    			this.errortextField = value;
    		}
    	}
    }

    It's off-topic, but you could make it much simpler:

    public partial class Response_Create_CustomerContact
    {
    	public string CustomerAccountD365 { get; set; }
    	public string Source { get; set; }
    	public string CustomerNoNAV { get; set; }
    	public bool Error { get; set; }
    	public string ErrorText { get; set; }
    }

    Anyway, if your question is how to iterate a collection, this class isn't really important.

    What's the type of the object you want to iterate? Maybe Response_Create_CustomerContact[, List<Response_Create_CustomerContact>, ArrayList or something.

    A solution that works in all these cases is using IEnumerable. Like this:

    System.Collections.IEnumerable enumerable = aCollection;
    System.Collections.IEnumerator enumerator = enumerable.GetEnumerator();
    
    while (enumerator.MoveNext())
    {
    	System.Object value = enumerator.get_Current();
    }

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,001 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,833 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans