Re: Integration of Purchase Orders
I don't usually give away free code as I need to feed my family, etc., but I'm having a good afternoon.
What you need to do change the source for the item mapping to use a script. In the script, you have to do something rather fancy. You need to connect to the GP company database in SQL, and create the relationship via eConnect. This can be done at the database level without web services or .NET applications. This code makes it happen:
DECLARE
@intStatus int, @outErrStatus int, @outErrMsg varchar(255)
EXEC @intStatus = taCreateItemVendors
@I_vITEMNMBR = 'ENTER Item Number here',
@I_vVENDORID = 'ENTER Vendor ID here',
@I_vVNDITNUM = 'ENTER Vendor Item Number here',
@O_iErrorState = @outErrStatus OUTPUT,
@oErrString = @outErrMsg OUTPUTif @intStatus <> 0 or @outErrStatus <> 0
BEGIN
if exists(SELECT 1 FROM DYNAMICS..taErrorCode (NOLOCK) WHERE ErrorCode = @outErrStatus)
select @outErrMsg = rtrim(ErrorDesc) FROM DYNAMICS..taErrorCode (NOLOCK) WHERE ErrorCode = @outErrStatus
else
select @outErrMsg = 'Unknown eConnect error encountered - taCreateItemVendors'
END
SELECT
@outErrStatus as ErrorStatus, @outErrMsg as ErrMessage
Note that the last line of my code returns two variables just indicating whether the creation was successful or not. That might help you decide what to do next. You could even log the eConnect error to the Integration Mgr error log.
You then need to set the mapping value with a line something like
CurrentField.Value = SourceField("Items.Item Number").Value
Check the syntax against the IM User Guide, as that's from memory and not cross checked.
FYI on best practice. It would not be preferred for you to open a connection to the database for every line of the integration. It's best to open the connection in the "Before Integration" event and set it to a global variable. I think you'll find examples of how to do this in CustomerSource Knowledgebase. Then you can use the global variable in the item mapping script.
Ron Draganowski
Senior Solution Developer
Olsen Thielen Technologies, Inc.St Paul, Minnesota
rdrag@ottechnologies.com
http://www.ottechnologies.com
Find me on LinkedIn: http://www.linkedin.com/in/rondraganowski