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 :
Microsoft Dynamics AX (Archived)

Update Customer Status

(0) ShareShare
ReportReport
Posted on by 634

Hi Guys,

I have a request that I need to update the customer's Classification Id to " Inactive " through a job if below three conditions are met.

1. There is no record exists in the table ForecastSales with this customer for the last 12 months ( we have fields end date and start date in this table)

2. There is no open orders for this customer Account in the sales table

3. There is nothing invoiced to this customer account for the last 12 months 

how can I check these conditions and update the customer status  through X++ Code.

Thanks in Advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahmoud Hakim Profile Picture
    17,887 on at

    you can make job in sql server and use the following code

    update CUSTTABLE  set custclassficationid = " your group" where CUSTTABLE.ACCOUNTNUM in (select distinct (c.ACCOUNTNUM) from custtable c where c.ACCOUNTNUM in(select distinct(s.CUSTACCOUNT)  from SALESTABLE s where s.SALESSTATUS =1  )

    or c.ACCOUNTNUM in (select distinct (f.CUSTACCOUNTID)  from ForecastSales f where year(f.ENDDATE) > year(GETDATE())-1  )

    or c.ACCOUNTNUM in (select distinct(v.ORDERACCOUNT) from CUSTINVOICEJOUR v where year(v.INVOICEDATE) > year(GETDATE())-1 )

    )

  • D365  beginner Profile Picture
    634 on at

    hi Sukrut,

    Thanks for the reply if you have time, Could you just show me 1 full example how the code should be ? considering the second point itself.

  • D365  beginner Profile Picture
    634 on at

    Hi Mahmoud / Sukrut

    Thanks for the reply, I am not familiar with the date formats in X++. how to write the code to retrieve the data between today and last 12 months.

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    There are so many ways to achieve this.One way is to calculate the start date & end date, pass the values to table buffer and loop them. I used salesTable for example and you can replace any table buffer of your choice.

    static void DateInterval(Args _args)

    {

       SalesTable salesTable;

       TransDate startDate, endDate;

       int i;

       endDate = today();

       i = year(endDate) - 1;

       startDate   = mkDate(dayOfMth(endDate), mthOfYr(endDate), i);

       while select salesTable

           where salesTable.DeliveryDate >= startDate

           && salesTable.DeliveryDate <= endDate

       {

           info(strFmt("%1", salesTable.DeliveryDate));      

       }

    }

  • Verified answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Please use the following job to update classification Id on the customer.

    I don't have sufficient data to test it. So, execute it and let me know if anything is missing.

    static void CustClassification(Args _args)
    {
    CustTable custTable;
    ForecastSales forecastSales;
    SalesTable salesTable;
    boolean canCreateRecord;
    TransDate startDate, endDate;
    CustInvoiceJour custInvoiceJour;
    int i;

    endDate = today();

    i = year(endDate) - 1;
    startDate = mkDate(dayOfMth(endDate), mthOfYr(endDate), i);

    while select custTable
    //where custTable.AccountNum == "XYZ"
    {
    canCreateRecord = true;

    // Condition 1: No record exists in the table ForecastSales
    select firstOnly forecastSales
    where forecastSales.CustAccountId == CustTable.AccountNum
    && forecastSales.StartDate >= startDate
    && forecastSales.EndDate <= endDate;

    if (forecastSales.RecId != 0)
    {
    canCreateRecord = false;
    }

    // Condition 2: No Open Orders
    select firstOnly salesTable
    where salesTable.InvoiceAccount == CustTable.AccountNum
    && salesTable.DocumentStatus == DocumentStatus::None;

    if (salesTable.RecId != 0)
    {
    canCreateRecord = false;
    }

    // Condition 3: There is nothing invoiced to this customer account
    select firstOnly custInvoiceJour
    where custInvoiceJour.InvoiceAccount == CustTable.AccountNum
    && custInvoiceJour.InvoiceDate >= startDate
    && custInvoiceJour.InvoiceDate <= endDate;

    if (custInvoiceJour.RecId != 0)
    {
    canCreateRecord = false;
    }

    if (canCreateRecord == true)
    {
    ttsBegin;
    custTable.selectForUpdate(true);
    custTable.CustClassificationId = "Inactive";
    custTable.update();
    ttsCommit;
    }
    }
    }

  • D365  beginner Profile Picture
    634 on at

    Hi Sukrut & Chaitanya,

    Thanks a lot. it works fine.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans