web
You’re offline. This is a read only version of the page.
close
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++

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    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

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
Martin Dráb Profile Picture

Martin Dráb 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans