Customization Example

The following example illustrates a way to add custom functionality to a guidelines and restrictions check. Customer one wants to set up custom guideline checks for their customer Finger Foods Bodega, used as an example, who wants a specific vendor to be the only supplier of certain items. Specifically, Finger Foods Bodega would like all frozen pizzas that they resell to have the cheese sourced from the example vendor Cheese Are Us. To accomplish this, Customer one will use the postItemGRCheck script hook and use an extension table.

  1. Create a generic standard guideline object called MUSTUSEVENDOR.
    mustusevendor_standard_guideline
  2. Create an Extension Table in the Extension Table Definition form.
    1. Specify Company as the supported symbol for MUSTUSEVENDOR.
    2. Add rows for the extension table definition in the Columns tab.
    vendor_restrictions_company
  3. Open the company object for your customer. Add a row in the Extension Tables tab and specify the Vendor and Standard Guideline that you created in step 1.
    extension_tables_company
  4. Write code for the script hook in the FGUIDELINE symbol.
    FGuideline_script
    The hook script contains the following code:
    Option Strict Off
    Imports System
    Imports System.Data
    Imports System.Collections.Generic
    Imports System.Diagnostics
    
    
    Class HookScript
     Inherits FcProcFuncSetEventHook
    
    Function postGRItemCheck () As Long
    	Dim retVal As Long = 1
    	Try
    		If _FORMULAGLINGR Is Nothing OrElse _FORMULAGLCUSTOMERS Is Nothing Then
    			Return 1
    		End If
    		Dim Items() As String = _FORMULAGLINGR
    		Dim Customers() As String = _FORMULAGLCUSTOMERS
    
    		For Each customer As String In Customers
    			Dim ds As DataSet = ObjectDataSet("COMPANY", customer, "HEADER;MATRIX")
    			Dim MustUseList As New List(Of VendorMustUse)
    			MustUseList.Clear()
    			For Each customTableRow As DataRow In ds.Tables("FSCOMPANYMATRIX_0").Select()
    				Dim mustUse As New VendorMustUse
    				'In FSCOMPANYMATRIX_0 extension table for customer FIELD2=ITEM, 
    				'In FIELD4=VENDOR, FIELD6=STD GUIDELINE TEXT
    				mustUse.item = customTableRow("FIELD2")
    				mustUse.description = customTableRow("FIELD3")
    				mustUse.vendor = customTableRow("FIELD4")
    				mustUse.stdGR = customTableRow("FIELD6")
    				MustUseList.Add(mustUse)
    			Next
    
    			'If there is an item for the formula that matches an item in the "Must Use" 
    			'extension table, create a new row in the result table.
    			For Each item As String In Items
    				For Each must As VendorMustUse In MustUseList
    					If item = must.item Then
    						Dim grLineId As Integer = 1
    						Dim tempDs As DataSet = ObjectDataSet("", "", "RESULT")
    						Dim rows() As DataRow = tempDs.Tables("FSFGUIDELINERESULT").Select("OBJCODE='" & item & "'")
    						If rows.Length > 0 Then
    							grLineId = rows.Length + 1
    						End If
    						Dim newResultRow As DataRow = GetNewRow("", "", "RESULT")
    						newResultRow("OBJTYPE") = "0"
    						newResultRow("OBJCODE") = must.item
    						newResultRow("OBJDESCRIP") = must.description
    						newResultRow("STDSTMTTXT") = must.stdGR.Replace("(&Vendor)", must.vendor)
    						newResultRow("FORMULA") = _OBJECTKEY
    						newResultRow("GR_LINE_ID") = grLineId
    						RowUpdate("", "", "RESULT", newResultRow)
    						CommitNewRow("", "", "RESULT", newResultRow)
    					End If
    				Next
    			Next
    		Next
    
    	Catch ex As Exception
    		retVal = -1
    		MessageList("Exception:" & ex.ToString)
    	End Try
    
    	Return retVal
    End Function
    
    Class VendorMustUse
    	Public item As String
    	Public description As String
    	Public vendor As String
    	Public stdGR As String
    	Public Sub New()
    	End Sub
    End Class
    
  5. Run a guideline check on a formula. Specify the company in step 4 in the Customer field and click Check Guidelines. The custom guideline is added to the Standard Guideline field.
    If the customer is referenced on the formula, it will already be in the Customer field.
    guideline_check_item_guidelines
    This example is to show one scenario, but given the flexibility of scripting, any number of scenarios for custom guideline checks are possible.