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, ...
Answered

Issue with JSON format

(0) ShareShare
ReportReport
Posted on by 1,883

Dear all,

I have custom service which return list of data. But while its returning the data the list class also returning all parameter methods which is associated with service/List class. Please how can I fix this issue the list parameters that I don't required in json format. And I can't remove the parameter from class while its using for other service methods in same service class.

[DataContractAttribute]
class salesProj
{
   YearBase years;
   Name salesMan;
  ProjId projId;
  InvoiceDate invoiceDate;
  AmountMST invoiceAmountmst;

}

[ DataMemberAttribute('Year')]
public  YearBase parmInvoiceYear(YearBase _invoiceyear = years)

{

  years = _invoiceyear;

return years;

}

[ DataMemberAttribute('InvoiceAmount')]

public AmountMST parmInvoiceAmount(AmountMST _invoiceAmount = invoiceAmountmst)

{

 invoiceAmountmst = _invoiceAmount;

return  invoiceAmountmst;

}

[ DataMemberAttribute('ProjId')]
public ProjId parmProjId(ProjId _projectId = projId)
{

  projId = _projectId;

return   projId;

}

[ DataMemberAttribute('Salesman')]
public Name parmSalesman(Name _salesMan =  salesMan)

{

  salesMan = _salesMan;

return  salesMan;

}

[SysEntryPointAttribute(true),AifCollectionTypeAttribute("return" , Types::Class, classStr(salesProj))]
public List getprojTotalCurrentYearAmount()
{
  salesProj salesClassObj;

  List saleslist = new List(Types::Class);

   salesClassObj = new salesProj();


   salesClassObj.parmInvoiceYear(2021);
   salesClassObj.parmInvoiceAmount(this.currentYearProjSales());

   saleslist.addEnd(salesClassObj);

     return saleslist;

}


C# Web api

 [HttpGet]
        [Route("api/getProjSales")]
        public HttpResponseMessage GetProjSales()
        {

            CallContext callContext = new CallContext();
            callContext.Company = "ENPR";
            callContext.Language = "en-us";

            testcustomerClient client = new testcustomerClient();
            custClass[] salesProj = client.getProjSales(callContext);
            List saleslist = new List();
            foreach (var item in salesProj)
            {
                saleslist.Add(item);
            }

            return Request.CreateResponse(HttpStatusCode.OK, saleslist);

        }
        
        //Json formart
        
        [{"InvoiceAmount":25072.43,"InvoiceDate":"1900-01-01T12:00:00","ProjId":"","Salesman":"","Year":2021}]
        
        How can I remove "InvoiceDate":"1900-01-01T12:00:00","ProjId":"","Salesman":"", above format while list class from AX its returning all parameters.

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

    You can create a new data contract class with the data you want and return this new data contract instead of the one that you're using at the moment.

  • Faqruddin Profile Picture
    1,883 on at

    If I create new data contract again I have to create service nodes and service group deployement. That means for every new service operatione Data contract and new service URL. This way it takes time. I need all operations projects, customers, sales etc all in one service url. But once I return data it should be related to that parameters only. Not all.

  • Martin Dráb Profile Picture
    237,884 Most Valuable Professional on at

    Why do you think that creating a new contact class and modifying code of a single service operation requires creating a completely new service and even a new service group?

  • Martin Dráb Profile Picture
    237,884 Most Valuable Professional on at

    You need do decide what you want. If you insist on having a single operation returning everything, then don't complain that it does return everything.

    But it doesn't look like a good design. Why can't you create a single service with three operations, one of projects, one for customers and one for sales?

    Also, consider if you can't meet your requirements with standard services, namely the query service or document services.

  • Faqruddin Profile Picture
    1,883 on at

    I manage by creating new contract class with single service. Once I called service operations its referring now new contract classes.

    Thank you.

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 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans