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

In X++ OnClosing Event.

(0) ShareShare
ReportReport
Posted on by 1,215

Hi guys,

my requirement when i am creating new lead i want must be filled in Contact details so that i wrote onClosing Event below the Code.

[ExtensionOf(formStr(smmLeadTable))]
final class SmmLeadTable_TWI_Extension
{
    /// 
    ///
    /// 
    /// 
    /// 
    [FormEventHandler(formStr(smmLeadTable), FormEventType::Closing)]
    public static void smmLeadTable_OnClosing(xFormRun sender, FormEventArgs e)
    {
        FormDataSource fds = sender.dataSource('smmLeadTable');
        smmLeadTable leadTable = fds.cursor();
        LogisticsPostalAddress logisticsPostalAddress;
        DirPartyTable dirpartytable;

        select leadTable
           exists join dirpartytable
             where dirpartytable.RecId == leadTable.Party
              exists join logisticsPostalAddress
                  where logisticsPostalAddress.PrivateForParty == dirpartytable.RecId;
        if (leadTable)
        {
            throw error("Must be filled in Phone!");
        }
    }

}

Now, in this code after filed in Contact details and close the form came error.

And sometime after closed in smmLeadTable form 'must be filled in phone'  in listapge throwing  also One form only it's used in  menuitem FormViewOpiton <grid>

what to be done two kind of error.

Thanks.

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Your select statement is not linked to the current record at all. Since you already have the current leadTable cursor at hand, you should not do a "select leadTable" because that would replace your current leadTable buffer with whatever comes out of your select statement.

    If you want to find the phone number for this lead, select something like this:

    select firstonly LogisticsElectronicAddress where logisticsElectronicAddress.PrivateForParty == leadTable.Party && logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Phone;

    Also, as my code indicates, phone numbers are stored in LogisticsElectronicAddress, not LogisticsPostalAddress.

    About your second issue, unfortunately I don't understand your description. Could you try to describe it more clearly? Thanks!

  • Riyas ahamed F Profile Picture
    1,215 on at

    thanks for your replay Nikolaos Mäenpää,

    in LogisticsPostalAddress coming a Address in SmmLeadTable so that i wrote a code.

    The new lead created and once filled in a address then close form came error again ?

    what should i do ?

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    So what code do you have in your system now?

    And what is your functional requirement? Check that a postal address (LogisticsPostalAddress) exists or check that a phone number (in LogisticsElectronicAddress) exists?

    Also, I suggest debugging your code, that usually gives you quite a good understanding what's happening under the hood.

    The code in your original message is not going to work. It just searches for any party that has address and that is related to any lead in the system. Then, if it finds such party, it throws an error. 

  • Riyas ahamed F Profile Picture
    1,215 on at

    i got a is there no LogisticsElectronicAddress

    but i tried in your logic same it is not working once filled in contact details then i will try close form

    came "Must be filled in phone" what did i mistake.

    below the code.

    [ExtensionOf(formStr(smmLeadTable))]

    final class SmmLeadTable_TWI_Extension

    {

       /// <summary>

       ///

       /// </summary>

       /// <param name="sender"></param>

       /// <param name="e"></param>

       [FormEventHandler(formStr(smmLeadTable), FormEventType::Closing)]

       public static void smmLeadTable_OnClosing(xFormRun sender, FormEventArgs e)

       {

           FormDataSource fds = sender.dataSource('smmLeadTable');

           smmLeadTable leadTable = fds.cursor();

           LogisticsElectronicAddress logisticsElectronicAddress;

           DirPartyTable dirpartytable;

           select firstonly LogisticsElectronicAddress where logisticsElectronicAddress.PrivateForParty == leadTable.Party

               && logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Phone;

           if (!LogisticsElectronicAddress)

           {

               throw error("Must be filled in Phone!");

           }

       }

    }

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    Can you show a screenshot where we can see that this lead has a phone number?

  • Riyas ahamed F Profile Picture
    1,215 on at

    it's an address details by mistake.

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    So is it working now?

  • Riyas ahamed F Profile Picture
    1,215 on at

    No, still not working what could be causes and resolutions ?

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    I'm still waiting for the screenshot.

  • Riyas ahamed F Profile Picture
    1,215 on at

    587302.Capture.PNG

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans