Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Easiest way to pass multiple values back.

(0) ShareShare
ReportReport
Posted on by 527

So I have an external C# class project that I consume a soap connection and get 3 pieces of data back. Which I would like to pass back from the call I make in the class in X code. Below I was the boolean that I get back from the call and the coopfunds and amffunds that return a decimal number.

 public void GetBillToInfo(str Billto)
    {
        ExternalWebServices.GetBDFFund GetBDFFund = new ExternalWebServices.GetBDFFund();

        real CoopFunds = 0;
        real AMFFunds = 0;
        String50 errorMsg;

        var fund = "";
       
        var tempFund = GetBDFFund.GetMichelinFunds(Billto, CoopFunds, AMFFunds, errorMsg);
       
        return tempFund;

    }

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    RE: Easiest way to pass multiple values back.

    You seem to making a set of artificial problem. Using a class is much easier.

    For example:

    public MichelinInfo GetMichelinFunds(String billto)
    {
    	BasicHttpBinding httpBinding = new BasicHttpBinding();
    	EndpointAddress endPoint = new EndpointAddress(@"http://xxx.channel-fusion.com/asmx/FundByDealerNumber.asmx");
    	var soapClient = new FundByDealerNumberSoapClient(httpBinding, endPoint);
    	MichelinInfo data = new MichelinInfo();
    	
    	try
    	{
    		decimal coopFunds = 0;
    		decimal amfFunds = 0;
    		str strError = '';
    		
    		data.Success = soapClient.AvailableFunds(billto, ref coopFunds, ref amfFunds, ref strError, pass);
    		data.CoopFunds = coopFunds;
    		data.AMFFunds = amfFunds;
    	}
    	finally
    	{
    		if (soapClient)
    		{
    			soapClient.Close();
    		}
    	}
    
    	return data;
    }

    Usage from X :

    public void getBillToInfo(str _billto)
    {
    	ExternalWebServices.GetBDFFund getBDFFund = new ExternalWebServices.GetBDFFund();
    	ExternalWebServices.MichelinInfo michelinInfo = getBDFFund.GetMichelinFunds(_billto);
    	
    	real coopFunds = michelinInfo.CoopFunds;
    	real amfFunds = michelinInfo.AMFFunfs;
    }

  • KeithM Profile Picture
    KeithM 527 on at
    RE: Easiest way to pass multiple values back.

    My issue is getting the right  type between the C# class project and the d365 X type.  I am trying to use an array, but since its a system type and x is not is not complying.


    Error Cannot implicitly convert from type 'System.String[' to type 'str['. 

    pastedimage1676559802366v1.png

    c# class object

           public string[] GetMichelinFunds(String billto, decimal CoopFunds, decimal AMFFunds, string strError)
            {
                BasicHttpBinding httpBinding = new BasicHttpBinding();
                EndpointAddress endPoint = new EndpointAddress(@"http://xxx.channel-fusion.com/asmx/FundByDealerNumber.asmx");
    
                string[] michelinInfo = new string[3];
    
                var soapClient = new FundByDealerNumberSoapClient(httpBinding, endPoint);
                michelinInfo[0] = soapClient.AvailableFunds(billto, ref CoopFunds, ref AMFFunds, ref strError, pass).ToString();
                
                michelinInfo[1] = CoopFunds.ToString();
                michelinInfo[2] = AMFFunds.ToString();
    
                soapClient.Close();
    
                return michelinInfo;
    
            }

    x method:

        public void GetBillToInfo(str Billto)
        {
            ExternalWebServices.GetBDFFund GetBDFFund = new ExternalWebServices.GetBDFFund();
    
            real CoopFunds = 0;
            real AMFFunds = 0;
            String50 errorMsg;
    
            String30  michelinInfo[];
    
            michelinInfo = GetBDFFund.GetMichelinFunds(Billto, CoopFunds, AMFFunds, errorMsg);
                    
        }

  • Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    RE: Easiest way to pass multiple values back.

    The usual way in object-oriented programming is creating an object with three values and returning this object.

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

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans