Wednesday, February 3, 2010

Filter Lookups By Predefined Smart-list Favorite “Simple data level security method”

Sometimes you might need to restrict access to some items in your store for certain machines, which is currently not possible out of the box, this method is not totally restriction but it could help, I am using the smart list favorites to filter lookups, follow steps below to implement:

1. Go to smart list and add some filters on the inventory items smart list then save it as a favorite smart list.

2. Go to Items lookup and add the form to VBA, then add “ViewAll” button to the VBA.

3. Write the following code segments in VBA to disable the “ViewAll” and “Advanced Search” buttons after selecting the needed favorite:

Private Sub ViewAllItemNumbersbyItemNumber_AfterUserChanged()
ViewAllItemNumbersbyItemNumber.Enabled = False
PBAdvancedSearch.Enabled = False
End Sub

5. After loading the window we’ll need to register a macro that selects the needed favorite, the code will look like the following:

Private Sub Window_AfterOpen()
    'Dim CompilerApp As New Dynamics.Application
    Dim CompilerApp As Object
    Dim CompilerMessage As String
    Dim CompilerError As Integer
    Dim Commands As String
    ' Create link without having reference marked
    Set CompilerApp = CreateObject("Dynamics.Application")
    Commands = ""
    Commands = Commands & "local integer l_file_id; " & vbCrLf
    Commands = Commands & "local string pathname; " & vbCrLf
    Commands = Commands & "pathname = Path_GetForApp(1) + ""TEMP.MAC""; " & vbCrLf
    Commands = Commands & "l_file_id = TextFile_Open(pathname, 0, 0); " & vbCrLf
    Commands = Commands & "TextFile_WriteLine(l_file_id, ""  ActivateWindow dictionary 'SmartList'  form 'IV_Item_Number_Lookup' window 'IV_Item_Number_Lookup' ""); " & vbCrLf
    Commands = Commands & "TextFile_WriteLine(l_file_id, ""  MoveTo field 'ASI_LU_View_Button' item 5  # 'Restricted List...' ""); " & vbCrLf
    Commands = Commands & "TextFile_WriteLine(l_file_id, ""    ClickHit field 'ASI_LU_View_Button' item 8  # 'Rams' ""); " & vbCrLf
    Commands = Commands & "TextFile_Close(l_file_id); " & vbCrLf
    Commands = Commands & "if File_Probe(pathname) then " & vbCrLf
    Commands = Commands & "  run macro pathname; " & vbCrLf
    Commands = Commands & "end if; " & vbCrLf
    ' Execute SanScript
    CompilerError = CompilerApp.ExecuteSanscript(Commands, CompilerMessage)
    If CompilerError <> 0 Then
        MsgBox CompilerMessage
    End If
End Sub

6. Give your use the access to the modified form instead of the original and enjoy having your form looks like the below:

image 

Hope that this helps.

Regards,
--
Mohammad R. Daoud - CTO
MVP, MCP, MCT, MCBMSP, MCTS, MCBMSS
+962 - 79 - 999 65 85 
mohdaoud@gmail.com
mohdaoud.blogspot.com

No comments:

Related Posts:

Related Posts with Thumbnails