Monday, February 7, 2011

SysInfoAction Class - Go to a specific record from the Infolog - Microsoft Dynamics AX 2009

Today I had a requirement that would allow a user to go to a ContactPersonLookup form record from an infolog that would be showed when a user wants to send an email to a contac without an email address.

First I needed to get the ContactPersonId based on the contact's PartyID. The following method takes one parameter (PartyId) and goes trough a simple sql query to get the record I need:

ContactPersonId GetContactIdFromPartyID(DirPartyID _partyId)
{
    ContactPerson           contactPerson;
    ContactPersonId         contactPersonId;
    DirPartyRelationship    dirPartyRelationship;
    ;

    select ChildPartyId from dirPartyRelationship where dirPartyRelationship.ParentPartyId == _partyId;
    if(dirPartyRelationship)
    {
        select ContactPersonId from contactPerson where contactPerson.PartyId ==  dirPartyRelationship.ChildPartyId;
        if(contactPerson.ContactPersonId)
            contactPersonId = contactPerson.ContactPersonId;
        else
            contactPersonId = '';
    }
    else
        contactPersonId = '';


    return contactPersonId;
}

Then I call this method, delete a file and call the SysInfoAction class to accomplish the requirement:

contactPersonId = smmQuotationTable.GetContactIdFromPartyID(partyId);
        if(contactPersonId || contactPersonId != '')
        {
            WinApi::deleteFile(filePath+fileName);
            SysInfoAction = SysInfoAction_FormRun::newFormnameDesc(FormStr(ContactPersonLookup), "Navigate to this contact");
            info("This contact does not have an email address on file. \n Please add one before continuing","", SysInfoAction_TableField::newBuffer(ContactPerson::find(contactPersonId)));
        }



The result is the following infolog window:


By clicking the Show button or double-clicking the message, the user will be taken to the ContactPersonLookup form record I want them to add an email.

You can find more information here: http://www.axaptapedia.com/SysInfoAction_class

1 comment:

  1. The code to get the ContactPersonId could be simplified by the following:

    ContactPersonId GetContactIdFromPartyID(DirPartyID _partyId)//Earias - 2/7/2011
    {
    ContactPerson contactPerson;
    ContactPersonId contactPersonId = '';
    DirPartyRelationship dirPartyRelationship;
    ;

    select ChildPartyId from dirPartyRelationship where dirPartyRelationship.ParentPartyId == _partyId;
    if(dirPartyRelationship)
    {
    select ContactPersonId from contactPerson where contactPerson.PartyId == dirPartyRelationship.ChildPartyId;
    if(contactPerson.ContactPersonId)
    contactPersonId = contactPerson.ContactPersonId;
    }

    return contactPersonId;

    }

    By setting the EDT variable to '', if nothing is found will be empty. This is good as I don't have to have the variable twice as shown in the original post.

    ReplyDelete

Thank you for your thoughts. Your comment will appear in my blog shortly after review.

Have a great day!