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,881

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.

  • Faqruddin Profile Picture
    1,881 on at
    RE: Issue with JSON format

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

    Thank you.

  • Martin Dráb Profile Picture
    232,038 Most Valuable Professional on at
    RE: Issue with JSON format

    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.

  • Martin Dráb Profile Picture
    232,038 Most Valuable Professional on at
    RE: Issue with JSON format

    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?

  • Faqruddin Profile Picture
    1,881 on at
    RE: Issue with JSON format

    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.

  • Verified answer
    Martin Dráb Profile Picture
    232,038 Most Valuable Professional on at
    RE: Issue with JSON format

    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.

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

#2
Martin Dráb Profile Picture

Martin Dráb 232,038 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans