Friday 16 August 2013

EP: AX Lookup: using SetMarkedRows(IEnumerable)

// Get the roles converted into keys
IEnumerable<IAxViewRowKey> viewKeys = getViewDataKeys(e.LookupControl.LookupDataSetViewMetadata);

lookup.SetMarkedRows(viewKeys);

--------------------------------------------------------------------------------
///


    /// Get the view datakeys based on the provided Segments
    /// Written by Mallik
    private List getViewDataKeys(DataSetViewMetadata viewMetaData)
    {
        DataSetViewRow row;
        string Roles = "";
        String lSegments;
        String[] roles = Roles.Split('-');
        IAxaptaRecordAdapter axRecord;
        TableMetadata tableMetaData = MetadataCache.GetTableMetadata(TableMetadata.TableNum("smmBusRelSegmentGroup"));
        List viewDataKeys = new List();
        try
        {
            // Retrieve the current row.
            row = AvaAnnouncementsDS.GetDataSet().DataSetViews["AvaAnnouncements"].GetCurrent();
            Roles = row.GetFieldValue("Segments").ToString();
            roles = Roles.Split('-');
            // For each Segment
            foreach (string role in roles)
            {
                using (axRecord = AxSession.AxaptaAdapter.CreateAxaptaRecord("smmBusRelSegmentGroup"))
                {
                    // Try to retrieve a list of the items.
                    axRecord.ExecuteStmt("select * from %1");//where smmBusRelSegmentGroup.Segments==" + role);

                    while (axRecord.Found)
                    {
                        lSegments = axRecord.GetField("SegmentId").ToString();
                        if (lSegments.Trim() == role.Trim())
                        {
                            // Create dictionary
                            Dictionary dict = new Dictionary();
                            dict.Add("SegmentId", lSegments);
                            // Create indexes
                            List index = new List(1);
                            index.Add(tableMetaData.DefaultUniqueIndex);
                            // Get viewdatakey  Add Item to list
                            viewDataKeys.Add((IAxViewRowKey)AxViewDataKey.CreateFromDictionary(viewMetaData, dict, index.ToArray()));
                            break;
                        }//if end
                        axRecord.Next();
                    }//  while end
                }//using end
            }//for end
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;

            // Determine whether the exception can be handled.
            if (AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory) == false)
            {
                // The exception was fatal and cannot be handled. Rethrow it.
                throw;
            }
        }
        return viewDataKeys;
    }

Update NuGet package to new MS D365FO version

1. Import the NuGet package files from LCS for that particular version please take the PU version files only. a. Goto LCS-->Asset Libra...