Get listitem by listId

lock
push_pin
done
Beantwortet
1

Hello. 

When it comes to defining udef in Sales with respect to lists there are 2 ways.

1. Creating a user defined field and assign a standard list to it. 
2. Creating a user defined field and assign a user defined list to it. 

I have problems with getting the item value from a standard list. 

In the table UDefField the only reference to a standard list table is the field listTableId as far as I can see.
If I have defined a userdefined field that points to one of the standard entities (ie, associate, sale stage, project status) and get a the item value id, how can I then fetch the item value if the only lookup field I have is the listTableId ? https://docs.superoffice.com/en/database/tables/udeffield.html

I can see there are functions agent.GetListIdByListName("name") and NSMDOListItem item = agent.GetListItem("listname", itemId) but I cannot see a way to get listitem when I only have the listTableId

18. Mai 2025 | 02:04 PM

Alle Antworten (1)

Hi Ummair,

There are a couple variations, but generally use the MDOAgent to get all lists, and then from that get all list items or one particular list item. Something like this should get you started.

NSMDOAgent mdoAgent;
Integer listId = 2;
Integer listItemId = 5;

NSMDOListItem GetMDOListByListId(Integer listId)
{
  NSMDOListItem[] lists = mdoAgent.GetList("lists", true, "", false);
  foreach(NSMDOListItem item in lists)
  {
    if(item.GetId() == listId)
    {
      return item;
    }
  }
  throw "List Not Found";
}

NSMDOListItem[] GetMDOListItemsByListId(Integer listId)
{
  NSMDOListItem list = GetMDOListByListId(listId);
  String listName = list.GetType();
  return mdoAgent.GetList(listName, true, "", false);
}

NSMDOListItem GetMDOListItemById(Integer listId, Integer listItemId)
{
  NSMDOListItem list = GetMDOListByListId(listId);
  String listName = list.GetType();
  NSMDOListItem item = mdoAgent.GetListItem(listName, listItemId);
  return item;
}

NSMDOListItem list = GetMDOListByListId(listId);
printLine("Found list: " + list.GetId().toString() + ": " + list.GetType());

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

NSMDOListItem itemItem = GetMDOListItemById(list.GetId(), listItemId);
printLine("Found item: " + itemItem.GetId().toString() + ": " + itemItem.GetName());

printLine("---------------------------");

NSMDOListItem[] listItems = GetMDOListItemsByListId(list.GetId());

foreach(NSMDOListItem item in listItems)
  printLine("Found list item: " + item.GetId().toString() + ": " + item.GetName());

printLine("done");

Hope this helps!

9 h, 27 m vor | 11:37 AM

Antwort hinzufügen