Forum Discussion

fizzledrizzle's avatar
fizzledrizzle
New Contributor III
10 months ago

Run Data Managment as an admin?

Howdy,

Background: I have a data management job that runs a Business Rule. I have created a dashboard with a button that can trigger this data management step. 

Problem: As an Administrator I can run the data management job, or I can click the dashboard button. As a user when attempting to use the button the following error happens: "Summary: Error processing Data Management Step 'xxx'. Unable to execute Business Rule 'yyy'. Object reference not set to an instance of an object." I have read that this is really just a catch all error. 

I think I have narrowed the problem down and believe it is because the users do not have permissions on the BatchHarvest Folder (which is referenced in the job). 

So, one question I have is: can a Data Managment job be triggered to run "as an admin" that I could assign to the button?

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    Hi fizzledrizzle ,  While permissions might be causing the issue, its not what the error is telling us.  The error means that a variable is being assigned a null value, or a variable is being referenced while null (nothing assigned to it).

    Its likely trying to assign something that an admin can read (in the code), and a user cannot, like access to a file

    Since there is no debugger, we have to write things to the error log until we find the thing causing the error.  I'd look  in the business rule and the args being passed in by the button for things like code that brings in a member, like an entity where security may prevent a user from being able to see the entity while an admin can.

  • JackLacava's avatar
    JackLacava
    Honored Contributor

    Permissions on DM jobs are typically related to the security groups assigned to Scenarios, check them out - there is one property specific to DM...

    Beyond that, I'd second what RobbSalzmann says - identify the actual line that fails, by logging messages, e.g.:

    ' ... doing something, then
    [...]
    Brapi.ErrorLog.LogMessage(si, "Step 1 done")
    ' ... doing something more...
    [...]
    Brapi.ErrorLog.LogMessage(si, "Step 2 done")
    ' .... and again ...
    [...]
    Brapi.ErrorLog.LogMessage(si, "Step 3 done")

    If you then tell us the actual line, we might be able to say more about what the actual problem is.

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    The error you're getting is saying one of the parameters is null (Nothing) in the call to the XFFile constructor:

    Dim targetFileData As New XFFile(targetFileDataInfo, String.Empty, sourceXFFileEx.XFFile.ContentFileBytes)

    My guess is the user doesn't have access to File Share\Applications\... and the sourceXFFileEx object is null.

    Add this  log entry (line 4) and see what happens for the admin and for the user:

    Dim sourceXFFileEx As New XFFileEx    
    sourceXFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.FileShare, $"Applications\{appNameOrig}\Batch\Harvest\{sourceFile}",True,True)
    Dim isFileNull As Boolean = (sourceXFFileEx Is Nothing)
    BRApi.ErrorLog.LogMessage(si, $"sourceXFFileEx isFileNull: {isFileNull}")
    
    

     

  • fizzledrizzle's avatar
    fizzledrizzle
    New Contributor III

    Thanks RobbSalzmann. I added the line and here are the results:

    User: sourceXFFileEx isFileNull: True

    Admin: sourceXFFileEx isFileNull: False

    The "Get File: " & sourceFile" does result in the file name for both users and admins.

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    Nice work!  This shows us that sourceXFFileEx is null when the user runs the code.
    Have the user check to see if they can view the files in the system file explorer tab:

     

     

  • fizzledrizzle's avatar
    fizzledrizzle
    New Contributor III

    Howdy! Thank you for your help with the ErrorLog JackLacava. Below a code snippet from the BR that is erroring when a user runs it, but does not error when an "Administrator" runs it:

    Dim appNameOrig As String = si.AppName
    Brapi.ErrorLog.LogMessage(si, "Declare App Name")
    
    Dim appDir As String = BRApi.FileSystem.GetFileShareFolder(si, FileShareFolderTypes.ApplicationRoot, api)
    Brapi.ErrorLog.LogMessage(si, "Declare App Directory for ApplicationRoot")
    
    Dim sourceDir As String = BRApi.FileSystem.GetFileShareFolder(si, FileShareFolderTypes.BatchHarvest, api) & "\"
    Brapi.ErrorLog.LogMessage(si, "Declare App Directory for BatchHarvest")
    
    Dim files As String() = Directory.GetFiles(sourceDir) 
    Brapi.ErrorLog.LogMessage(si, "Declare list of files from Source Directory")
    
    For Each FileName In files    
    
    	Dim sourceFile As String = Path.GetFileName(FileName)
    	Dim targetFile As String = sourceFile
    	Dim targetDir As String = "Documents/Public/TXM_SFTP"
    	If sourceFile.StartsWith("TXM_") And sourceFile.contains(".csv") Then
    		'Get the file
    		Dim sourceXFFileEx As New XFFileEx    
    		sourceXFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.FileShare, $"Applications\{appNameOrig}\Batch\Harvest\{sourceFile}",True,True)
    		Brapi.ErrorLog.LogMessage(si, "Get File: " & sourceFile)
    		'Save the file                
    		Dim targetFileDataInfo As New XFFileInfo(FileSystemLocation.ApplicationDatabase, targetFile, targetDir)
    			Brapi.ErrorLog.LogMessage(si, "Save File: Line 106")
    		Dim targetFileData As New XFFile(targetFileDataInfo, String.Empty, sourceXFFileEx.XFFile.ContentFileBytes)
    			Brapi.ErrorLog.LogMessage(si, "Save File: Line 108")
    		BRApi.FileSystem.InsertOrUpdateFile(si, targetFileData)
    			Brapi.ErrorLog.LogMessage(si, "Save File: Line 110")
    		BRApi.FileSystem.DeleteFile(si,FileSystemLocation.FileShare, $"Applications\{appNameOrig}\Batch\Harvest\{sourceFile}")
    			Brapi.ErrorLog.LogMessage(si, "Save File: Line 112")
    		Brapi.ErrorLog.LogMessage(si, "Save File: " & sourceFile)
    	End If
    Next    

    The error must have occurred after line 25 above because i received the log "Save File: Line 106" but then it errors. so somewhere after this line:

    Dim targetFileData As New XFFile(targetFileDataInfo, String.Empty, sourceXFFileEx.XFFile.ContentFileBytes)

    let me know if you spot anything or suggestions on next steps.

    • JackLacava's avatar
      JackLacava
      Honored Contributor

      Indeed that looks like the attached XFFile is not valid. Can you change the source file retrieval to not fail gracefully, i.e. use this:

      sourceXFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.FileShare, $"Applications\{appNameOrig}\Batch\Harvest\{sourceFile}", True, False)

      You might get an exception with some more details. If you want to keep the graceful failure, you can also check sourceXFFileEx.AccessLevel, which can be equal to DataAccessLevel.NoAccess / .ReadOnly / .AllAccess, hence indicating if the user has access to the file.

      Since it's on the fileshare, you can also try using the features in System.IO.File instead of BRApi - not best practice, but might work. There should be examples in Snippets.

  • fizzledrizzle's avatar
    fizzledrizzle
    New Contributor III

    Howdy,

    I have verified that they do not have access to this folder. How are permissions to the "File Share" folders managed? I can grant permissions to the "Application Database" folders, but not the "File Share" folders.