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

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?

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.

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.

Related

How to make an API endpoint in Laravel, that can be used to search any table we want?

Background
Let us consider a hypothetical scenario. Suppose we have five different tables in our database,
Customers
Categories
Products
Orders
OderDetails
Our client wants us to add a search bar to the frontend, where a user can search for a specific product and upon tapping the search button, matching products has to be displayed on the frontend.
My Approach for Tackling This Problem
In order to add the aforementioned functionality, I came across the following strategy.
πŸ‘‰ I would add an input box to ender the product name and a submit button.
πŸ‘‰ Upon pressing the submit button, a GET request will be sent to the backend. On the query parameters, the product name that has been entered by the user will be included
πŸ‘‰ Once the GET request is received to the backend, I will pass it down to the ProductsController and from within a method defined inside the ProductController, I will use the Product model to query the products table to see if there are any matching results.
πŸ‘‰ If there are any matching results, I will send them to the frontend inside a JSON object and if there aren't any matching results, I will set a success flag to false inside the JSON object and send it to the frontend
πŸ‘‰ In the frontend, if there are any matching results, I will display them on the screen. Else, I will display "No Results Found!"
Problem with My Approach
Everything works fine if we only want to search the products table. But what if, later our client tells us something like "Remember that search functionality you added for the products? I thought that functionality should be added to orders as well. I think as the list of orders by a user grows and grows, they should be able to search for their previous orders too."
πŸ‘‰ Now, since in our previous approach to search products was implemented in the ProductController using the Product model, when we are adding the same functionality to Orders, WE WOULD HAVE TO DO THE SAME THINGS WE DID IN THE ProductsController AGAIN INSIDE THE OrdersController USING THE Order model. It does not take seconds to understand that this leads to duplication of code.
Problem Summary
❓ How do we add an API endpoint in laravel for a search functionality that can be used to search any table in our database and get results, instead of the search functionality being scoped to a specific controller and a corresponding model?
A good start would be to create a trait called something like searchable and add it to all the models you want to search and put any shared logic between the different models in there. Possibly you'd want to manually allow different columns so in each model you have an array of searchable columns which you'd refer to in your trait.
Your controller would have to point to the related model and call a method in the trait that searches.
As others have pointed out this is a high level question so I won't go too much in detail. Of course there are a million ways to implement this, just try and keep shared logic in place.

Query to find order products for related accounts in Dynamics CRM

On the Accounts form, I want to be able to show all Order Products for that Account and any related Account. My aim is to give the user an easy way to see what has been bought by a customer with several related offices (Accounts).
Any idea how this can be done?
There is a way to do this with a plugin. The general steps would be:
Ensure the view that is used on the order product subgrid on the Account form is not used anywhere else.
Make a unique change to the view columns or filter criteria that will let you distinguish it from other views. For example, you could add a condition of "createdon contains data", which most likely would not be used anywhere else
Create a pre-RetrieveMultiple plugin on Order Product.
In the plugin, get the query from the input parameters and check for the "createdon contains data" condition. If it does not exist, exit the plugin.
If the condition exists, this is the view you want to update. In the query, find the condition that has accountid.
Use the accountid to retrieve related child and parent accounts.
Update the query with a condition checking if accountid is in the list of all the accountids you retrieved.
The query should now return all the relevant order products and display them on the Account form.
This is a rather involved solution with only the high level steps outlined here.
Here is a link that shows an example of modifying a query in a pre-retrievemultple plugin:
https://hachecrm2011.wordpress.com/2013/07/19/filtering-views-by-intercepting-retrieve-multiple-queries-with-a-plugin/

Customize Data Studio reports with different filters for different users

I have many end users for my reports. Some of them want to look at all website data, some just section A, some section B, etc. For my own sanity and not having to create the same report over and over with different filters, I'm wondering if there's either:
A way to provide a link to a report where the link tells data studio what filter to apply to the report
A way to filter the report based on the user who's logging in.
I have the impression that neither of these is possible, and it seems like people are reluctant to have one dashboard that they have to proactively filter for their section (I'm still going to try that). But I'm hoping that there's perhaps something I didn't know about.
This is possible using Custom bookmark links (doc). The Drill down table example (doc) shows how you can create a table with records linking to a second page of the dashboard with different filters. You could use this to create filter pre-sets for different users groups.
This is currently not possible.

Remove the inbuilt filter contact ID from Incident Reports in Customer Portal in Oracle RightNow

This is about displaying a "Report on Incidents" based on the "Organization" on the Customer Portal. We will be entering the Organization in an input box and then on clicking on "submit". The Incident Report should be displayed only for that Organization.
This is happening but the "Logged In" contacts Id (c_id) is also getting passed as a filter to that Incident Report.
Is it possible to remove the c_id filter that's imposed on the above Incident report? How do I remove this contact ID filter from Incident report?
Someone suggested to use the pre_report_get_data hook and then unset the Contact ID (c_id) filter. But I was not able to figure out how to do that.
Can someone give me a code snippet to remove the c_id filter using pre_report_get_data hook? Or some other solution to this problem.
Copy the report that you want to edit to a new version, then edit the filters of the report as you see fit. You won't be able to edit the default canned reports directly, but with a copy, you can edit it completely.
EDIT
Contact filters are always applied on Customer Portal filters because of the user model on Customer Portal. CP expects that a user on the web is a specific customer and should only have access to contact data that is specific to the particular contact in the user session. This is a security mechanism and is working as intended.
If the goal is to display data from reports that might have contact data related to it, but should be exposed to all contacts, then you should probably write a custom widget that runs a ROQL or Analytics API query directly, but be wary of the potential to expose other customer data if implemented incorrectly.
If you want to use the pre_report_get_data hook, then it's pretty simple to enable the hook in the settings/hooks.php file. Point the hook to the model and method that you want the hook to call. Then, edit the passed array of data to unset c_id from the filters array, as was mentioned in the other post.
$rnHooks['pre_report_get'][] = array(
'class' => 'filter_report',
'function' => 'report_run',
'filepath' => ''
);
That tells the hook engine to call the report_run() method in the filter_report model. These are typically example code files in CP, so you should have most of the work already done to implement that hook.
function report_run($hookData)
{
if($hookData['data']['reportId'] == '100335') //Change the report ID to the report that you need to call
{
unset($hookData['data']['filters']['c_id']); //you'll need to lookup the key of the filter in the report to figure out which one to unset
}
}

How to show records related to upper records too in a subgrid?

How can I build a subgrid that displays related records both of the current record and records above it, and can it contain complex conditions ?
One of my requirements is this:
I want to put a subgrid in Account form showing the related Contacts of the current Account, and also include the Contacts related to Accounts above the current one if a Two Options attribute of the contact is set to Yes.
Specifically, I'm looking at the Company Name on Contact to establish it's related to an Account.
I'm at a loss and start to doubt it's doable.
Not an out of the box solution but if you don’t mind losing the sub grid command bar functionality you can use the following concept that displays a fetchxml inside a sub-grid.
Step 1 - would be to get all related accounts ids using a fetch or odata
Step 2 - construct a fetchxml with OR filter to get all contacts

Resources