Category Archives: Dynamic CRM

Alternative forms for an entity based on user ownership

Hi. Long time no post!

In dynamics CRM, according to policies of your business, you can restrict users access to records using security role feature. For example a user can see only opportunities she/he owns. By at some points, some sales people need to have basic information about the business accounts they interact with, they want to know if the account already bought a product from the company or not. The easiest solution is ask the record owner, and the owner would tell the expert/salse person only detiails that is not considered secure.

But this solution causes lot of time waste. There is a feature in Dynamics CRM forms that you can define alternative forms. These forms could be seen by all roles or only specific roles. In out scenario, We want to users see to kind of forms, based on their ownership for the record. If the salesperson own the record she can see all details, if not alternate form is rendered to her. Is it achievable using a code like the following on form load event:

 

   if(CurrentRecordOwner!=CuurentActiveUser)
	   {
		         var currentFormId = Xrm.Page.ui.formSelector.getCurrentItem();

           $.each( Xrm.Page.ui.formSelector.items.get(),function(index,item){
              
                  if (item.getLabel()=="New Form Name" && currentFormId.getLabel()!="New Form Name")
                  {
                           form=item;
                  }
              });
      
          form.navigate();
	   }

It works fine! yes in first load of the form. But when forms redirect tho alternative for, from that moment, if you want to open another record of that type, CRM will use the last loaded form type, I meant if you are the owner you will see the alternate version. I inspected the loaded scripts and saw an amazing behavior. The script I binded to main form event load, was not loaded for the alternative one. Although in alternative form propeties I could see that the scipt bind for load event was there!

So in alternative form properties, I removed the corresponding script and bind it again and it worked! So I could redirect user correctly based on condition.

Advertisements

Using Webservices in Dynamics CRM plug-ins

Hi

Sometimes you need calling a web service inside a plugin, like a scenario we encountered. We need a plugin for an activity Status change event, which calls a web service out side of the CRM server. In this situations if you add a web service reference in plug-in code in visual studio and deploying it to CRM server, it would not work using the config items in App.config.

What is the solution ?

You should manually config the web service, I mean hard code it like below :


BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress endpoint = new EndpointAddress("http://webservice?wsdl");
var webserviceClient= new WEbServiceClient(binding, endpoint);

Enabling CORS on tomcat

Long time no post!

Hi

As i have already told, our Dynamic CRM Customizations deals with ABAS ERP software.

To respond some requirements of Service Processing subsystem, in a CASE form we want a button that by clicking on, product information get loaded to the form. User inputs a serial number, and by that SN, a request made to ERP server and products information get back as response.

ABAS ERP developing team already developed a SOAP web service which sync customer data between ERP and CRM. It works fine when it used as a service reference int a CRM plugin. But when it comes to use web service in a html client using Java Script, story changes. First of all I had to find a JS lib to parse SOAP messages. It was easy, I googled and found javascriptsoapclient. But as the origin of CRM and web service host are different, browser does not allow js to request the web service and throws “Access-Control-Allow-Origin” error.

I am new to Java developed web services and also to apache tomcat web. If it was a .net web service, I could solve problem by adding required headers. But the web service is a Java project and developed using Eclipse IDE. After a lots of research I found that I cand add CORS (Cross Origin resource sharing) to tomcat, but for versions higher than 7.0.41 !

I installed latest version and read lots of documents and questions around web. In official docs of tomcat, it says by adding some xml tags you can enable CORS for entire apps hosted in tomcat. As it seems it is not actually that easy.

What I had to do? I had to download two libraries mentioned in this  guideline and them to lib folder of tomcat. It is the best solution, but in addition to add those libraries to the lib folder of tomcat, you also  have to add them to lib folder of the application you want to have CORS enabled.

Regards.

Restricting views based on security roles even for quick search view

Hi..

In a company I currently work (I told you before), we have lots of staff and teams that each staff belongs to one of them. To apply security rules to CRM system, we have already some tools, like “Security Role” and “Field Level Security”.

You can define which entities a team or user can access an how far. I mean you can restrict a user to see only his/her activities or hide some entities for him/her.

But there are some situations that you want to show only specific view of an entity to a team. Say you want to only names and owner of “Account” entity to team “X”.

When a user opens “Accounts”, bunch of views are there to filter result for him/her. But we want user to have only one view of “Account” and all other views being hidden from her/him.

I googled and found this useful solution. You can easy filter views based on security rules. You can even say which view is the default one, when a user/team wants to see records of some entity.

Using the solution, I created a system view, assigned to team “X” as a default view for “Accouint”. Every thing works fine, team members only see name and owner in their views, but when they use quick search box, view changes and all other fields become visible for team members.

That is where plug-in comes to the play. By creating a plugin on pre-operation of “RetriveMultiple” message of account entity you can restrict the fields returned to the user requested the view.

Hope it helps.

Custom Advance Find view in Dynamics CRM

Hi again.

As you know there is a service part in dynamic CRM where you can track customers request for product failure or you can define your services, contracts and etc.

To make “Case” more usable for our company`s needs and requirements and make it easier for support team to work with Dynamics CRM, some customization suggested. One of them was to show a grid of records with same serial number of current Case in the Case form.

I did some research and found this useful article, but it did not work in IE and Firefox, I mean the grid is not shown in the form! So why?

Let see how could we show a custom grid (Like what you see in Views of an entity) in a form.

First you should now that by posting a form to “/AdvancedFind/fetchData.aspx” you can get a result containing a view of requested entity. But this form needs some parameters as below:

FetchXml : The query you pass to get data

LayoutXml: The columns you want to be shown on view

EntityName: Entity you want to query

DefaultAdvFindViewId: Id of a default view you created for your custom need

(Notice: This view should have exact columns as you have in LayoutXml)

ViewType: (I dont know :D)

How could you get “FetchXml “?

is it easy, just go to views tab of entity you want to query, click on New Personal View, In saved views find the View you want to use, then click on Download Fetch XML.

For LayoutXml, you can use XrmToolBox, and get layout of view you want.

So what ? As I said the solution provided by the mentioned article, does works perfect in chrome but have problems in IE and firefox. To make it work in those browsers, instead of creating the form dynamically using js code, I hard-coded form elements in string and then post it, as below:

<br />
	var innerform='<form name="vDynamicForm" method="post" action="'+ gContext.getServerUrl()+'/AdvancedFind/fetchData.aspx">'+

			'<input type="hidden" name="FetchXml" value="'+Instance.FetchXml+'">'+
			'<input type="hidden" name="LayoutXml" value="'+Instance.LayoutXml+'">'+
			'<input type="hidden" name="EntityName" value='+Instance.Entity+'>'+
			'<input type="hidden" name="DefaultAdvFindViewId" value='+Instance.QueryId+'>'+
			'<input type="hidden" name="ViewType" value="1039">'+

			'</form>';

 

 

Create new record using current form values in dynamic crm

Currently I am working on a new customization for dynamics CRM customization that requires to copy fields from a form and create a new record using JS.

Copying text or numeric values was easy, like the below :

var attValue = Xrm.Page.data.entity.attributes.get(attname).getValue();

But for Optionset or Money attributes the scenario was different. For those types to copy to you have to do :

var attVal = Xrm.Page.data.entity.attributes.get(attname).getValue();
var newattVal= attVal!=null ? {Value:attVal.toString()}:null;

It meas you have read “Value” from the atttribute to get what you want. Finally yo save a new record with values I read using current form, I utilized the CrmRestKit library like below:

CrmRestKit.Create( 'entityname', listofaatributes, false )
				.fail( function(){
				//console.log('error accoured');
				} 
				)
				.done( function ( data, status, xhr ) { 
				

				} );

Saving File With Java Script From Dynamic CRM Form

Recently I received new requirements for Dynamics CRM customization. One of them is to make way for user to click on a button on a form, and save a file which is being filled from the fields of entity that button has been placed on.

So the first thing that came into my mind, was using Java Script to save the file. I embedded a html web resource in the entity form, and inside the html web resource I referenced jquery and a library for saving file with js called FileSaver.jsIn the body of that html file, I only put a button and made a click event listener with jquery for it. When the button clicked, Unique Id of entity is read and saved in a varaible, then the content of file we wanted to save is filled and finally saved by calling filesaver.js API.

The file is in EKs format, the one which is used by abas ERP for running some commands (I dont know much about abas ERP).

The solution works fine with Chrome and Firefox, but …. You know IE …. yeah the problem is there. As far as I researched, the problem cant be solved by using activex with js, but I could not get it to work.

I hope I would find a solution and tell you about it….