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)

Lookup to retrieve entire record

(1) ShareShare
ReportReport
Posted on by

Hello,

I have a simple custom lookup that is using a view. I want to be able to retrieve the entire record of the selected row (and not just 1 field). I saw some examples, but wasn't able to get it to work correctly. Could someone point me in the right direction?

public void lookup()

{

   SysTableLookup sysTableLookup =   SysTableLookup::newParameters(tablenum(CustomView), this);

   Query query = new Query();

   ;

   sysTableLookup.addLookupField(fieldnum(CustomView, FieldA), true);

   sysTableLookup.addLookupField(fieldnum(CustomView, FieldB));    

   query.addDataSource(tablenum(CustomView));

   sysTableLookup.parmQuery(query);

   sysTableLookup.performFormLookup();

}

Any help would be appreciated.

Thanks,

Charu

*This post is locked for comments

I have the same question (1)
  • Gertjan Profile Picture
    1,200 on at

    For what reason would you like to retrieve the complete record? You can add additional fields using the sysTableLookup.addLookupField, but you cannot add all fields using one method. Retrieving all fields for all records in the lookup might be cost inefficient?

  • Community Member Profile Picture
    on at

    Hi Gertjan,

    The data is not unique, so I would like to specifically know what record the user selects, otherwise it will not be possible for me to retrieve the correct record. (ex. field A is not unique). I can add recid to the addlookup, but then I still want the value of fieldA to be displayed in the form control and retrieve just the recId? Is this possible?

  • Suggested answer
    Gertjan Profile Picture
    1,200 on at

    Good evening,

    Yes, you can add multiple fields by adding additional lookup fields, using the method sysTableLookup.addLookupField(). If you can identify which fields make a record unique for ths scenario, you can add those fields in the lookup. No need to add all fields of a record and the user directly sees the fields that matter. You can add as many fields as you want, but try to limit it to the fields necessary for the task.

    Hope this information helps.

    Gertjan

  • Community Member Profile Picture
    on at

    Adding fields by using addLookupField() is fine, I am adding the relevant fields. I think, my question wasn't clear. Say I have fieldA and fieldB and there are duplicates for fieldA. So my issue is just getting the value of fieldA is not enough, I need the combination of FieldA and FieldB. Anyway to do this?

  • Dick Wenning Profile Picture
    8,705 Moderator on at

    ok,

    add more sysTableLookup.addLookupField

    but also add a refrecId for the real value, otherwise no unlike item is returned

  • Community Member Profile Picture
    on at

    Hi, I am facing a similar scenario. Could you please share, if you had found a solution for this.

  • Suggested answer
    B K Sharma Profile Picture
    737 on at

    Hi Jadhav,

    The problem with you is that a combination of field is unique in the lookup view and you want to save this unique record in your base form where you are going to give custom lookup.

    Once i faced same issue in ax 2009 and i come to get solution by creating a refrecid field in base table and saving the recid of lookup view.

    Please check image

    Untitled123.png

    Untitled123.png

    Please mark verified if this answers your question.

    Thanks

  • Community Member Profile Picture
    on at

    Hi Sharma,

    The problem is - I dont want to show the RefRecId in the lookup. Cause the value is meaningless. Is there any way to hide it.

    Thanks.

  • Suggested answer
    B K Sharma Profile Picture
    737 on at

    Yes, you can hide it but you have to use form as lookup and in this form you just hide the recid field in grid, now when you select the record the recid will set in base tables refrecid field and also you have to take combination of fields in your base table for identification if required.

    Call lookup form in lookup method using this code

    public void lookup()
    {
    Args args = new Args();
    FormRun itemLookUp;
    ;
    args.name(formstr(WCL_JMSItemLookupForm));
    args.parm(Num2str(WCL_JointMeasurementLine.JMSRecID,0,0,0,0));
    args.record(WCL_JointMeasurementHeader);
    itemLookUp = new FormRun(args);
    itemLookUp.init();
    this.performFormLookup(itemLookUp);
    }

    pls provide your mail, i will share xpo to you.

    Please mark verified if this answers your question.

    Thanks

    B K Sharma

  • Community Member Profile Picture
    on at

    Hi Sharma,

    Thanks for your response. I work in D365. I have a control - "Add selection" and I have 3 methods added to it at form level

       [Control("String")]

       class fromAddSelection

       {

           public void jumpRef()

           {

               element.addressJumpRef(FromAddressType.selection(), this.valueStr());

           }

           public void lookup()

           {

               TMSAddressType      tmsAddressType;

               TMSRouteTable::lookupAddress(this, str2enum(tmsAddressType, FromAddressType.valueStr()));

           }

           public boolean modified()

           {

               boolean         ret;

               InventLocation  warehouse;

               VendTable       vendTable;

               ret = super();

               switch (FromAddressType.selection())

               {

                   case TMSAddressType::Warehouse:

                       LogisticsLocation               logisticsLocation;

                       InventLocationLogisticsLocation

                                     inventLocationLogisticsLocation;

                       InventLocation                  inventLocation;

                     logisticsPostalAddress=logisticsPostalAddress::findRecId(str2int64(fromaddSelection.valueStr()));

                       select RecId from logisticsLocation

                           where logisticsLocation.RecId == logisticsPostalAddress.Location

                               join InventLocation from inventLocationLogisticsLocation

                                   where inventLocationLogisticsLocation.Location == logisticsLocation.RecId

                                       join InventLocationId,Name,RecId from inventLocation

                                           where inventLocation.RecId == inventLocationLogisticsLocation.InventLocation;

                       warehouse = inventLocation;

                       fromAddress = TMSAddressPhone::initFromInventLocation(warehouse, false, str2int64(fromaddSelection.valueStr()));

                       fromAddSelection.text(warehouse.InventLocationId);

                       break;

               }

               element.setFromFields(FromAddressType.selection(), FromAddSelection.text());

               element.setWarehouseFields(warehouse.InventLocationId, warehouse.InventSiteId);

               VendorCode.text(vendTable.AccountNum);

               VendInvoiceCode.text(vendTable.InvoiceAccount);

               return ret;

           }

       }

    Here in the lookupAddress method, Here i am returning the PostalAddressRecId as main reference to the modified method which is helping in doing the other process. I want hide this value alone in the UI .

    static void lookupAddress(FormStringControl _ctrl, TMSAddressType _addressType)

       {

           SysTableLookup          sysTableLookup;

           Query                   query;

           QueryBuildDataSource    queryBuildDataSource;

           boolean                 selectedNone;

           switch (_addressType)

           {

               case TMSAddressType::Warehouse:

                   sysTableLookup          = SysTableLookup::newParameters(tableNum(TMSWarehouseLocation), _ctrl);

                   query                   = new Query();

                   queryBuildDataSource    = query.addDataSource(tableNum(TMSWarehouseLocation));             sysTableLookup.addLookupfield(fieldNum(TMSWarehouseLocation, InventLocationId));            sysTableLookup.addLookupfield(fieldNum(TMSWarehouseLocation, Name));              sysTableLookup.addLookupfield(fieldNum(TMSWarehouseLocation, PostalAddressRecId),true);

                   break;

               default:

                   selectedNone = true;

                   break;

           }

           if (!selectedNone)

           {

               sysTableLookup.parmQuery(query);

               sysTableLookup.performFormLookup();

           }

       }

    My ID, nithya.nishyas@gmail.com. Please share the xpo. Kindly suggest, if can understand the complexity.

    Thanks

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