Getting logged in user  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Getting logged in user

Postby DannyC » Thu Oct 16, 2014 1:24 pm

Hi,

How can I get the logged in user?

My scenario...I have a custom field (boolean) in Staff Maintenance which says if a user is allowed to delete sales order lines.

I just need to read the logged-in user custom field and if not allowed to delete sales order lines, stop the deletion. I have got the bit which fires when a line is deleted, now I just need to read the users custom field & back out of the line deletion.
Can you help?

Cheers

Danny
User avatar
DannyC
Senpai
Senpai
 
Posts: 647
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Getting logged in user

Postby Mike.Sheen » Thu Oct 16, 2014 1:47 pm

DannyC wrote:I just need to read the logged-in user custom field and if not allowed to delete sales order lines, stop the deletion. I have got the bit which fires when a line is deleted, now I just need to read the users custom field & back out of the line deletion.


Danny,

Something like this will work (substitute the "AllowSalesOrderLineDelete" with the name of your own custom field) :

Code: Select all
Dim hasPermission As Boolean
For Each customFieldValue As JiwaApplication.CustomFields.CustomFieldValue In JiwaApplication.Manager.Instance.Staff.CustomFieldValues
    If customFieldValue.CustomField.PluginCustomField.Name = "AllowSalesOrderLineDelete" Then
        hasPermission = CBool(customFieldValue.Contents)
        Exit For
    End If
Next


EDIT: I should explain that JiwaApplication.Manager.Instance.Staff is the staff business logic for the currently logged in user - it's a shared (static) property and will always be the staff maintenance business logic associated with the current user - so all fields you see on the staff maintenance form are accessible via that.

I also suspect you may be approaching this wrong. I believe it would be better to add your own abstract permission "AllowSalesOrderLineDelete" and then you can set that permission against user groups and maintain that in the normal permission maintenance built into Jiwa. Let me know if that's something you want to explore and I can provide an example.

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2476
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 766

Re: Getting logged in user

Postby DannyC » Fri Oct 17, 2014 5:05 pm

Mike,
Yes, I'd like to know about adding our own abstract permission "AllowSalesOrderLineDelete". I think that could be a more elegant solution but I am not sure my client would be setting up different User Groups though, so I am basically replicating in Jiwa 7 what is already in place in 6.5.13 (customised).

I found that I was getting an error on the line
hasPermission = CBool(customFieldValue.Contents)
so I made it a string variable and all OK now.

I am using the following line to fire a Private Sub
AddHandler salesOrderForm.SalesOrder.SalesOrderLineRemoving, AddressOf DeleteLine

but the line
Private Sub DeleteLine(sender As Object, e As System.EventArgs )

is giving a compile error
Method 'Private Sub DeleteLine(sender As Object, e As System.EventArgs )' does not have a signature compatible with delegate 'Delegate Sub SalesOrderLineRemoving...

I basically need a way to back out of the line delete, a bit like the old RtnCancel. I've seen a previous suggestion elsewhere just to do another Read request, but I don't want to read the Sales Order again, I just want to get back to the line state before the delete event.

Cheers
User avatar
DannyC
Senpai
Senpai
 
Posts: 647
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Getting logged in user  Topic is solved

Postby Mike.Sheen » Mon Oct 20, 2014 9:44 am

DannyC wrote:I am using the following line to fire a Private Sub
AddHandler salesOrderForm.SalesOrder.SalesOrderLineRemoving, AddressOf DeleteLine

but the line
Private Sub DeleteLine(sender As Object, e As System.EventArgs )

is giving a compile error
Method 'Private Sub DeleteLine(sender As Object, e As System.EventArgs )' does not have a signature compatible with delegate 'Delegate Sub SalesOrderLineRemoving...


That event signature looks like this:
Code: Select all
Public Event SalesOrderLineRemoving(sender As Object, e As System.EventArgs, ByVal item As SalesOrderLine)


So just add the last parameter and you should be working. We left that event there simply as a compatibility bridge from V6 script - you can also use the salesOrderForm.SalesOrder.SalesOrderLines.Removing event - which is much the same, but is consistent with our standard design pattern.

DannyC wrote:I basically need a way to back out of the line delete, a bit like the old RtnCancel. I've seen a previous suggestion elsewhere just to do another Read request, but I don't want to read the Sales Order again, I just want to get back to the line state before the delete event.
Cheers


Throw a JiwaApplication.Exceptions.ClientCancelled exception to behave like the old rtnCancel of V6.

As for the permissions:

1. Insert an abstract permission into the table:
Code: Select all
INSERT INTO SY_FormsAbstractPermissions(RecID, SY_Forms_ClassName, Name, Description, ItemNo)
SELECT NewID(), 'JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm', 'Remove Sales Order Line', 'Allow removal of sales order lines',
(SELECT MAX(ItemNo) + 1 FROM SY_FormsAbstractPermissions WHERE SY_Forms_ClassName = 'JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm')


2. Add the plugin code to examine the permission when a delete of a line is starting and throw a clientcancelled if no permission
Code: Select all
     Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)            
      AddHandler salesOrderForm.SalesOrder.SalesOrderLines.Removing, AddressOf SalesOrderLines_Removing
    End Sub
   
   Public Sub SalesOrderLines_Removing(SalesOrderLine As JiwaSales.SalesOrder.SalesOrderLine)
      Dim permission As JiwaApplication.Security.UserGroup.AccessLevels = JiwaApplication.Manager.Instance.Staff.GetAbstractPermission("JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm", "Remove Sales Order Line")
      
      If permission <> JiwaApplication.Security.UserGroup.AccessLevels.Allow Then
         Throw New JiwaApplication.Exceptions.ClientCancelledException
      End If
   End Sub


3. Set the permissions - on the sales order entry form, utilities ribbon tab - choose Set Permissions then select the Abstract Permissions tab and locate the new permission "Remove Sales Order Line" - set the permission and save. Remember permissions are masked together for all groups the staff member belongs to, as well as the Default Abstract permission.
Permissions.JPG
Abstract Permissions


For completeness a plugin is attached demonstrating this.
Plugin Cancel Sales Order Line Remove.xml
Sample plugin
(32.8 KiB) Downloaded 435 times


Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2476
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 766

Re: Getting logged in user

Postby DannyC » Mon Oct 20, 2014 1:25 pm

Thanks again Mike. All sorted!
User avatar
DannyC
Senpai
Senpai
 
Posts: 647
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 8 guests