Adding AutoComplete Items with Dexterity

Dave DusekThis is a quick and easy way to add items to the AutoComplete list for a field.  I'm talking specifically about the AutoComplete property on a field. 

In this case, the customer didn't want to use the lookup window to select an existing item number, they wanted it to be in the AutoComplete list.  The problem is that in order for it to get into the AutoComplete list, you have to select or type it at least one time.  They wanted all of the items in the AutoComplete list right away without selecting or typing.  So this code does that for them.

The field we are targeting is the Item Number field.  This will populate any Item Number field in GP, but we need to pass a window field to the AutoComplete_AddStringValue() function, so in this case, we will use the SOP Entry window.  The code below was added on a form trigger so the user could select to update AutoComplete items.  This code could take a while depending on how may items they have, so you have to be careful when you run it and the SOP Entry window does have to be open.  Also, the AutoComplete tables are local tables, so this does have to be run on each machine for each user.

Example code to update AutoComplete data

 local boolean result;
local string litem;

range clear table IV_Item_MSTR;

get first table IV_Item_MSTR;
while err() <> EOF do
   litem = 'Item Number' of table IV_Item_MSTR;
    
    result = AutoComplete_AddStringValue(field 'Item Number' of window SOP_Entry of form SOP Entry, litem);
 
    get next table IV_Item_MSTR;
end while;

warning "Update Complete.";

Dave Dusek
Dynamics GP Developer Support

// Copyright © Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, https://opensource.org/licenses/ms-pl.html.)