Using Panatrack Flex Fields within eConnect

Using Panatrack Flex Fields within eConnect

When PanatrackerGP submits eConnect transactions, we pass along our flex fields in the event they can be used to update custom data within your GP system. This stored procedure provides a function that can be used to easily pull out a named flex field for use in your procedures. 

  1. /* This is a helper function to assist in intercepting eConnect messages triggered from the Panatracker system. 
  2.  * For some transactions, Panatracker loads an additional field in the eConnect message with structured data that 
  3.  * can be used to retrieve information that is collected by Panatracker, but not necessarily used by Dynamics. 
  4.  * This function would typically be called from a eConnect pre or post trigger to retrieve the special data. 
  5.  * 
  6.  * EXAMPLE USAGE: Panatrack_ParseData(@I_vUSRDEFND5, 'ReferenceField1')  --Will retrieve the data associated with the "ReferenceField1" field. 
  7.  */ 
  8.   
  9. IF EXISTS (SELECT * FROM sysobjects WHERE type = 'FN' AND name = 'Panatrack_ParseData') 
  10. BEGIN 
  11. DROP FUNCTION Panatrack_ParseData 
  12. END 
  13. GO 
  14.  
  15. CREATE FUNCTION Panatrack_ParseData 
  16.     ( 
  17.       @Input VARCHAR(8000), 
  18.       @TagName VARCHAR(30) 
  19.     ) 
  20. RETURNS VARCHAR(8000) 
  21. AS BEGIN 
  22.  
  23.     DECLARE @dataStartPos INT 
  24.     DECLARE @dataEndPos INT 
  25.     DECLARE @dataLength INT 
  26.     DECLARE @result VARCHAR(1000) 
  27.      DECLARE @startTag VARCHAR(30) 
  28.     DECLARE @endTag VARCHAR(30) 
  29.   
  30.     SET @startTag = '[' + @TagName + ']' 
  31.     SET @endTag = '[/' + @TagName + ']' 
  32.       SET @dataStartPos = CHARINDEX(@startTag, @Input)  
  33.     SET @dataLength = CHARINDEX(@endTag, @Input) - (@dataStartPos + LEN(@startTag)) 

  34.     IF @dataStartPos = 0  
  35.         SET @result = '' 
  36.     ELSE  
  37.         BEGIN 
  38.             SET @result = SUBSTRING(@Input, (@dataStartPos + LEN(@startTag)), @dataLength) 
  39.         END 
  40.    
  41.     RETURN @result 
  42.   END  
  43.   GO  
  44.    
  45.   GRANT EXECUTE ON Panatrack_ParseData TO DYNGRP 
  46.   GO