Ravi
Ravi

Reputation: 61

MS CRM Online Custom View - Need to show specific records in View for specific users (based on team)

I have entity "Work Order" for which I have defined many custom views. Work Orders can have records with statuses as "active ,cancelled, closed, inprogress, submitted" etc. My requirement is - currently logged in user who belongs to a specific team "sales representative" should be able to see all records on view.This can be done easily, but If current logged in user does not belongs to "sales representative" team, she should not be able to see "cancelled" records on view but all other record should be visible to her. How can I achieve this using custom filters if it is possible? Or by code changes?

Upvotes: 0

Views: 338

Answers (2)

Conor Gallagher
Conor Gallagher

Reputation: 1499

It is possible to do this with custom code. Without questioning the "why" you'd like to do this (possibly it's sensitive information or something?), you can achieve it using a RetrieveMultiple plugin registered on the pre-operation event. Within this plugin one of the input parameters passed in is called "Query" and will have a QueryExpression. You can simply add a filter to this query in the plugin and the relevant rows will be filtered out. Something like this:

var query = (QueryExpression)context.InputParameters["Query"];

var condition= new ConditionExpression()
{
    AttributeName = "statuscode",
    Operator = ConditionOperator.NotIn,
    Values = { 2, 3 } // Or whatever codes you want to filter!
};

query.Criteria.AddCondition(condition);

To check the current user you can grab the user id from the plugin context and retrieve the necessary info you would like to check.

Upvotes: 2

Ronan Raftery
Ronan Raftery

Reputation: 86

Doesn't sound like this is possible with advanced find alright. You may be able to achieve it using security roles though. If you could assign cancelled work orders to a specific team, and then organise your security setup so that users who are not sales representatives can't see work orders from that specific team, then it might work. Unfortunately you would have to reassign the cancelled work orders which is not always an option.

Otherwise, you might have to go with a separate view for cancelled work orders, out of the box advanced find should allow you present a blank grid of you are not on the right team. But now obviously you are not presenting a whole view of the work orders.

In general I would go with the security option, and just make it work. Any other option is just a stop-gap. Users can always create custom views, so if you don't lock down access using security roles, the data is still accessible in indirect ways.

Upvotes: 0

Related Questions