Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dexterity - Scrolling Window - field change 1

Status
Not open for further replies.

Borvik

Programmer
Jan 2, 2002
1,392
US
Sorry - another Dexterity question. It seems I'm full of questions these days.

Thanks to Dave, I was able to find the correct spot to work out a script to populate my 2 added fields to the scrolling window in the SOP_Entry form via the following script:
Code:
{
Name: PDP_SOP_Entry_LineFill
Description: IV_Item_MSTR_QTYS contains the data we want.
             It should already be set (according to debugger).
             Run on TRIGGER_FOCUS_FILL (LINE_FILL)
}

'(L) PDP Qty On Hand' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS;
'(L) PDP Net Available' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS - 'QTY Allocated' of table IV_Item_MSTR_QTYS;

Well I also need those fields to populate when the user types in a new item number - adding it to the order document.

I knew LINE_CHANGE wouldn't be the right trigger to attach to - as that runs when the line loses focus. The best place I figured would be the TRIGGER_FOCUS_CHANGE of the Item Number field within the scrolling window.

The script I have attached does indeed run, and I can get the entered Item Number and associated Location Code - but the table IV_Item_MSTR_QTYS is not locating the correct record.

I've tried setting the proper fields in the table, but it still doesn't update properly (tried watching the Local window during script debugger breakpoints).

Here are several variations of the script I've tried:
Code:
{
Name: PDP_SOP_Entry_LineItemChange
Description: IV_Item_MSTR_QTYS contains the data we want.
             Runs on Item Number change (TRIGGER_FOCUS_CHANGE)
			 in the scrolling window on form SOP_Entry
}
local string ITEMNMBR;
local string LOCNCODE;

ITEMNMBR = 'Item Number' of table SOP_LINE_WORK;
LOCNCODE = 'Location Code' of table SOP_LINE_WORK;
if not empty(ITEMNMBR) and not empty(LOCNCODE) then
	'Item Number' of table IV_Item_MSTR_QTYS = ITEMNMBR;
	'Location Code' of table IV_Item_MSTR_QTYS = LOCNCODE;
	'(L) PDP Qty On Hand' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS;
	'(L) PDP Net Available' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS - 'QTY Allocated' of table IV_Item_MSTR_QTYS;
end if;
The next one is not optimal I know - as it opens a separate copy of the IV_Item_MSTR_QTYS tables locally for the script instead of just using the one already attached to the form. I had to try it anyway.
Code:
{
Name: PDP_SOP_Entry_LineItemChange
Description: IV_Item_MSTR_QTYS contains the data we want.
             Runs on Item Number change (TRIGGER_FOCUS_CHANGE)
			 in the scrolling window on form SOP_Entry
}
local string ITEMNMBR;
local string LOCNCODE;
local anonymous table IvTemp;
local string table_name;

table_name = "IV_Item_MSTR_QTYS";

ITEMNMBR = 'Item Number' of table SOP_LINE_WORK;
LOCNCODE = 'Location Code' of table SOP_LINE_WORK;
if not empty(ITEMNMBR) and not empty(LOCNCODE) then
	open table IvTemp with name table_name;
	set 'Item Number' of table IvTemp to ITEMNMBR;
	set 'Location Code' of table IvTemp to LOCNCODE;
	'(L) PDP Qty On Hand' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IvTemp;
	'(L) PDP Net Available' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IvTemp - 'QTY Allocated' of table IvTemp;
end if;
Code:
{
Name: PDP_SOP_Entry_LineItemChange
Description: IV_Item_MSTR_QTYS contains the data we want.
             Runs on Item Number change (TRIGGER_FOCUS_CHANGE)
			 in the scrolling window on form SOP_Entry
}
local string ITEMNMBR;
local string LOCNCODE;

ITEMNMBR = 'Item Number' of table SOP_LINE_WORK;
LOCNCODE = 'Location Code' of table SOP_LINE_WORK;
if not empty(ITEMNMBR) and not empty(LOCNCODE) then
	set 'Item Number' of table IV_Item_MSTR_QTYS to ITEMNMBR;
	set 'Location Code' of table IV_Item_MSTR_QTYS to LOCNCODE;
	'(L) PDP Qty On Hand' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS;
	'(L) PDP Net Available' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS - 'QTY Allocated' of table IV_Item_MSTR_QTYS;
end if;
I've also tried the following one with variations of the get table line.
Code:
{
Name: PDP_SOP_Entry_LineItemChange
Description: IV_Item_MSTR_QTYS contains the data we want.
             Runs on Item Number change (TRIGGER_FOCUS_CHANGE)
			 in the scrolling window on form SOP_Entry
}
local string ITEMNMBR;
local string LOCNCODE;

ITEMNMBR = 'Item Number' of table SOP_LINE_WORK;
LOCNCODE = 'Location Code' of table SOP_LINE_WORK;
if not empty(ITEMNMBR) and not empty(LOCNCODE) then
	set 'Item Number' of table IV_Item_MSTR_QTYS to ITEMNMBR;
	set 'Location Code' of table IV_Item_MSTR_QTYS to LOCNCODE;
	get table IV_Item_MSTR_QTYS;
	'(L) PDP Qty On Hand' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS;
	'(L) PDP Net Available' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS - 'QTY Allocated' of table IV_Item_MSTR_QTYS;
end if;

I've run out of ideas on how to populate the IV_Item_MSTR_QTYS table for this trigger. I'm probably missing something very simple.

Anyway someone can nudge me in the right direction? Thanks.
 
Hi Borvik

I think you have missed something. I'll explain.

The Scrolling window fill script is executed just prior to an inherent copy from linked table to scrolling window command.

Because of this the code in the fill script (or triggers against the fill script), must read their values from the linked table and then populate the window fields.

If you can slow Dex down, you would see the fields in the fill script being populated in the window and then the rest of the fields being copied from the table buffer to the window.

So your fill script is correct.

However your script on the Item Number field is wrong. You need to read the values from the window fields and not the table buffer as the changes are not copied into the table buffer until the scroll change script is executed.

Here is the code you would need. You were looking at the table buffer instead of the window fields and you did not have a get table statement to read from the table.

{
Name: PDP_SOP_Entry_LineItemChange
Description: IV_Item_MSTR_QTYS contains the data we want.
Runs on Item Number change (TRIGGER_FOCUS_CHANGE)
in the scrolling window on form SOP_Entry
}
if not empty('Item Number' of window Line_Scroll of form SOP_Entry) and not empty('Location Code' of window Line_Scroll of form SOP_Entry) then
'Item Number' of table IV_Item_MSTR_QTYS = 'Item Number' of window Line_Scroll of form SOP_Entry;
'Record Type' of table IV_Item_MSTR_QTYS = 2;
'Location Code' of table IV_Item_MSTR_QTYS = 'Location Code' of window Line_Scroll of form SOP_Entry;
get table IV_Item_MSTR_QTYS;
if err() = OKAY then
'(L) PDP Qty On Hand' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS;
'(L) PDP Net Available' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS - 'QTY Allocated' of table IV_Item_MSTR_QTYS;
end if;
end if;

I am not sure why you were using an anonymous table. If you want to use a separate table buffer to ensure you do not change the values in the form's table buffer for that table, then place your code into a form level procedure or function and don't pass the table buffer as a parameter.

Functions and procedures will create a new table buffer instance for any table referenced in the code unless you pass the table as an inout parameter. This means that you can decide whether your functions and procedures use the same table buffer or create a new one.

Please note that temporary tables must be passed as parameters otherwise the function or procedure will create a new temporary table instance with zero records.

Here endeth the lesson.

David Musgrave [MSFT]
Senior Development Consultant
Escalation Engineer - Great Plains
Microsoft Dynamics Support - Asia Pacific

Microsoft Dynamics (formerly Microsoft Business Solutions)

Any views contained within are my personal views and
not necessarily Microsoft Business Solutions policy.
This posting is provided "AS IS" with no warranties,
and confers no rights.
 
Thanks Dave - that script worked.

Yea, the anonymous table I only tried because the other ideas I was trying weren't working.

Though I have to question some of your explanation.

My scripts were pulling the correct Item Number and Location Code from the table buffer just fine.

Just to test out a theory, I took my last trial that I posted an added the line that was setting the Record Type - making it look like:
Code:
{
Name: PDP_SOP_Entry_LineItemChange
Description: IV_Item_MSTR_QTYS contains the data we want.
             Runs on Item Number change (TRIGGER_FOCUS_CHANGE)
             in the scrolling window on form SOP_Entry
}
local string ITEMNMBR;
local string LOCNCODE;

ITEMNMBR = 'Item Number' of table SOP_LINE_WORK;
LOCNCODE = 'Location Code' of table SOP_LINE_WORK;
if not empty(ITEMNMBR) and not empty(LOCNCODE) then
    'Item Number' of table IV_Item_MSTR_QTYS = ITEMNMBR;
    'Record Type' of table IV_Item_MSTR_QTYS = 2;
    'Location Code' of table IV_Item_MSTR_QTYS = LOCNCODE;
    get table IV_Item_MSTR_QTYS;
    '(L) PDP Qty On Hand' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS;
    '(L) PDP Net Available' of window Line_Scroll of form SOP_Entry = 'QTY On Hand' of table IV_Item_MSTR_QTYS - 'QTY Allocated' of table IV_Item_MSTR_QTYS;
end if;

It worked - apparently that was all I was missing.

Thank you for the lesson Dave - as always you are a great help.
 
For a line that has already been saved reading from the table buffer will work. For a brand new line being added, it is very likely that the fields have not yet been copied to the table buffer. Please use the window fields for these scripts as using the table buffer is not guaranteed to work 100%.

When using the get table and change table commands you need to make sure you are populating all the fields in the key for the table. If you don't specify a key it means that the first key is to be used.

David Musgrave [MSFT]
Senior Development Consultant
Escalation Engineer - Great Plains
Microsoft Dynamics Support - Asia Pacific

Microsoft Dynamics (formerly Microsoft Business Solutions)

mailto:David.Musgrave@online.microsoft.com

Any views contained within are my personal views and
not necessarily Microsoft Business Solutions policy.
This posting is provided "AS IS" with no warranties,
and confers no rights.
 
Yea, that's what I figured (about the table buffer).

I wondered that about the Key - now that I got that concept grasped, it should make other adjustments I'm working on easier.

I've also been working on my own function to create SQL tables - based off the KB articles you pointed me to as well as your FAQs. It seems to be working (so far, there are a few adjustments I'm going to make so that it's completely self-contained) - but I'd like to run it past you before I turn it into a FAQ myself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top