{Dynamics Version 9.0} Execute custom action with all parameter types in Dynamics CRM Version 9.0

Dynamics Version 9.0 introduced the Xrm.WebApi namespace which provides all the methods to interact with dynamics CRM server from client side script.

Detailed Documentation – https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-webapi

However recently I was working on a project to upgrade the SOAP calls from client and replace them with the new Xrm.WebApi methods. Create/ delete/ update were kind of easy and was easily ported to the new API’s.

However then came the Actions. The client had actions which had many input parameters and which were getting invoked from the client using SOAP calls. We had to port them to the Xrm.WebApi. But in Xrm.WebApi we did not had any function like executeAction. But the Xrm.WebApi.execute came to our rescue.

Let’s first examine Xrm.WebApi.execute method. Microsoft documentation shows it like this –

Xrm.WebApi.execute(request).then(successCallback, errorCallback);

For the sake of brevity of this blog post, I am skipping the documentation of the parameters. For detailed information on the parameters, please refer the below Microsoft documentation link – https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-webapi/execute

 

So how to call an action with input parameters? For this post, I created an action named “new_TestAction”. The action is global. It has the following input parameters.

  • Name – Type (string)
  • Age – Type(string)
  • InputEntityReference – Type (EntityReference)
  • InputEntity – Type (Entity)
  • InputEntityCollection – Type(EntityCollection)

For entityreference, entitycollection and entity, I have kept the Entity as Account Entity. All set and done. Now the next step is to call the action. below is the sample code to create the request object. All the important parameters has been highlighted and appropriate comments put.

TestAction1: function (input1, input2, inputEntityReference, inputAccount, inputAccountCollection) {
        this.InputEntityReference = inputEntityReference;
        this.Input1 = input1;
        this.Input2 = input2;
        this.InputEntity = inputAccount;

        this.InputEntityCollection = inputAccountCollection;

        this.getMetadata = function () {
            return {
                boundParamter: null, // for entity action, put the entitysetname/ entitylogicalname here
                parameterTypes: {
                    "Input1": {
                        "typeName": "Edm.String",
                        "structuralProperty": 1 // Primitive Type
                    },
                    "Input2": {
                        "typeName": "Edm.String",
                        "structuralProperty": 1 // Primitive Type
                    },
                    "InputEntityReference": { // Entity Reference
                        "typeName": "mscrm.account",
                        "structuralProperty": 5
                    },
                    "InputEntity": { // entity
                        "typeName": "mscrm.account",
                        "structuralProperty": 5
                    },
                    "InputEntityCollection": { // entity collection
                        "typeName": "mscrm.account",
                        "structuralProperty":4 // collection type
                    }
                },
                operationType: 0, // 0 for action, 1 for function and 2 for CRUD
                operationName: "new_TestAction1"
            };
        };
    }

Next is the code to create this request object and pass the object to the action.

ExecuteAction: function () {
        debugger;
        var accountReference = {
            "@odata.type": "Microsoft.Dynamics.CRM.account",
            "@account.id": "9602CEB2-55F7-E711-A954-000D3A34A0AA"
        };
        var accountEntity = {
            "@odata.type": "Microsoft.Dynamics.CRM.account",
            "@account.id": "9602CEB2-55F7-E711-A954-000D3A34A0AA"
        };
        var accountEntityCollection =[
            {
            "@odata.type": "Microsoft.Dynamics.CRM.account",
            "@account.id": "9602CEB2-55F7-E711-A954-000D3A34A0AA",
            "name": "Test Account 1"
            },
            {
            "@odata.type": "Microsoft.Dynamics.CRM.account",
            "@account.id": "9602CEB2-55F7-E711-A954-000D3A34A0AA",
            "name": "Test Account 1"
            }];
        var requestObject = new TestAction1("Name", "Age", accountReference, accountEntity, accountEntityCollection);
        Xrm.WebApi.execute(requestObject).then(function (result) {
            debugger;
        },
        function (error) {
            debugger;
            console.log(error.message);
        });
    }

Simple isn’t it. I haven’t covered the other primitive types like – Decimal/ Int. They are pretty simple like for int, it is Edm.Int32.

Hope this helps!

 

-Debajit Dutta

(Dynamics MVP)

For consultation/ training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

 

 

Advertisements

Understanding SharePoint Document Locations for Entity based folder structure–Dynamics CRM + SharePoint integration

Recently I was handling a training in Dynamics where I was demoing the OOB CRM SharePoint integration.

Client was already using the OOB CRM-SharePoint configuration using entity based folder structure. Anyone getting confused what is meant by entity based folder structure? Well while configuring you get an option to select whether based on Account/ Contact.

I selected Account here. Not a big deal.

image

But here it gets interesting. What if I upload some documents for a child record of an account and then change the account for that child record?

To duplicate this, I followed the below steps

  • Created two accounts – Account A & Account B
  • Created a case – Case | Document Test for Account A
  • In the Documents Section, uploaded file named – Document 1.txt

Let’ see the folder structure in SharePoint after this operation.

image

No surprises here. As we have chosen Entity based folder structure, the document got uploaded for the case under the account for which the case has been logged.

Now let’s go ahead and changed the account of the case to Account B

image

Now if we go ahead an upload a Document for the case – Document 2.txt, it should roll up under Account B. Let’s see that if it happens.

I go ahead and upload the document. But surprisingly it is still uploading under Account A in SharePoint.

image

 

Strange isn’t it? But why it happens? To understand this we need to understand the Document Locations record that CRM uses to map to the corresponding folder in SharePoint.

The following are the document locations record that got created after we uploaded Document 1.txt.

image

As you can see, four document location records got created

  • One for entity – account
  • One for account record – Account A
  • One for entity – (case)incident
  • One for case record – Case| Document Test

As you can see all are named “Document on Default Site 1”. This is confusing. So let’s name it accordingly.

Below is the screenshot after renaming. Probably looks simpler now with the names.

image

Looks go ahead and create the document location record manually for Account B.

image

 

image

 

image

 

If you now come back to the Case record and move to the Documents section, you will find two document locations now but if you select the Account B Document Location record, you will find no upload button.

image

This is because the corresponding folder in SharePoint does not exist. Lets go and create that.

image

 

Now if you go ahead to the case and move to the Documents section, you would find both the Document Locations for previous and current account.

And if you now upload a document to the case for the current account, it goes and sits at the right place. And you can always switch back to see what were the documents uploaded for the previous account as well.

image

Hope this helps!

 

Debajit Dutta

(Dynamics MVP)

For training/ consulting/ tools, please visit www.xrmforyou.com

Documents Link missing in Navigation pane even after enabling Document Management in Dynamics Version 9.0

Recently I was in a training for a client where I was demoing the CRM – SharePoint  OOB integration. So I enabled the integration and then also enabled the Account Entity for Document Management.

However when I opened a Contact and tried to Navigate to the Documents section, I find no link in the Navigation Pane. Looked like the one below.

image

Bit embarrassing since just before that I told the participants that the document link would appear once I enabled the entity for Document Management.

Bit flummoxed, I checked for the relationship whether mistakenly I have made the relationship display to False. It was not the case.

Then jumped on to the form editor and clicked on the Navigation Pane and then much to my relief, I could see the Documents tab in the available relationships.

image

 

Just dragged the relationship on to the Common relationship area. Save and publish the customizations. And much to my relief I could see the Documents link in the Navigation Pane

image

 

Small thing. But saves you some moments if you know this.

 

Debajit Dutta

(Dynamics MVP)

For consulting/ tools/ training please write to us at info@xrmforyou.com or visit our website www.xrmforyou.com

{Fixed} Error while connecting to Dynamics 365 Version 9.0–Metadata contains a reference that cannot be resolved.

Recently one of our customers upgraded to Version 9.0 from D365 8.2 and then all of a sudden all the console jobs which used to connect to Dynamics CRM and were scheduled as batch jobs started failing.

Checking the event viewer we found out the following error – “Metadata contains a reference that cannot be resolved”.

Was curious to know and hence copied the portion of code which connects to CRM from batch job, into a separate console application. Sample code below

ClientCredentials clientCredentials = new ClientCredentials();

clientCredentials.UserName.UserName = “<username>”;
clientCredentials.UserName.Password = “<password>”;

            var proxy = new OrganizationServiceProxy(new Uri(“https://domainname.crm.dynamics.com/XRMServices/2011/Organization.svc”),
null, clientCredentials, null);

            <<<code to perform fetch>>>

 

It was failing while trying to create the proxy. The same code was working in Dynamics CRM version 8.2

Thought something changed in the service URL and hence copied and pasted the URL in the browser. Worked just fine.

So what can be the problem here.

So when I opened CRM in browser (firefox in this case), I just clicked on the padlock to view  the certificate information and then click on More Information (shown in screenshots below).

image

image

 

image

 

In the technical details I could see the Encryption protocol being used is TLS1.2

image

 

Just our of curiosity, I just added the below line of code before creating the proxy.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

 

Full code.

ClientCredentials clientCredentials = new ClientCredentials();

clientCredentials.UserName.UserName = “<username>”;
clientCredentials.UserName.Password = “<password>”;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

var proxy = new OrganizationServiceProxy(new Uri(“https://domainname.crm.dynamics.com/XRMServices/2011/Organization.svc”),
null, clientCredentials, null);

 

And voila it worked just fine.

I am still researching as to why I needed to use this in version 9.0 although TLS 1.2 was being used in the previous versions as well.

 

Hope this helps to resolve the issue and save some time.

-Debajit Dutta (Dynamics MVP)

For training/ consulting please visit www.xrmforyou.com

 

 

{Dynamics 365} Debug scripts for Dynamics 365 for phones using web browser

First of all Happy New Year to all my blog readers. It’s been sometime I have been writing something and I love the fact that I am back at quite early stage of the year.

New year, new assignment and on the very first week I am working on mobile enablement for a client. Now mobile can be Tablets/ Phone interface and here the customer was more interested towards using Dynamics 365 for Phones.

The client already had some pretty hefty scripts written on the forms and if you have already worked on enabling CRM for mobile you know the pain of debugging scripts.

Thankfully there is a trick of showing up mobile preview in browser

So if my Organization url is https://xrmforyou40.crm.dynamics.com and my org unique name is – orgffgh56 (you can find it out by going to Settings –> Customizations –> Developer Resources), the following url will show up the mobile mockup in the web browser.

https://xrmforyou40.crm.dynamics.com/nga/main.htm?org=orgffgh56&server=https://xrmforyou40.crm.dynamics.com

You might be thinking – What’s new in this? It’s been told so many times already in so many wonderful blogs.

Well yes! But there is a subtle difference to it.

The above URL will simulate how your Dynamics 365 will look in Tablets. Dynamics 365 for Phones can be tricky considering the functionalities are more limited than tablet and also the UI rendering is different from the way it renders in the tablets.

Now a small twist in the URL

https://xrmforyou40.crm.dynamics.com/nga/main.htm?org=orgffgh56&server=https://xrmforyou40.crm.dynamics.com&phone=true

 

Just adding the Phone query string at the end will do wonders and it will render just like the way it will show up in your phone.

 

Hope this helps!

 

(For consulting/ training contact us at info@xrmforyou.com)

Configuring Live Assist (Preview) for Dynamics 365.

Awesome read on live assist

Nishant Rana's Weblog

Let us see how we can configure Live Assist step by step.

First, go to Applications tab of the Dynamics 365 Administration Center.

Select Live Assist for Dynamics 365 and click on Manage.

Click on Accept to give permission to the app.

Select the Dynamics 365 Instance and provide your email id, accept the terms and conditions and click on Submit.

This configures the Live Assist on the specified Dynamics 365 Instance and also sends the email to the email id specified.

Once the configuration is done, we can see the new Live Assist section added in our Settings area.

There we can click on Admin URL of Live Assist for further configuration.

Clicking on it opens the Admin Center.

Click on Confirm and Authorize.

The Dashboard of the admin center.

The Get Started page.

Code Snippet that we can use to enable Live Assist in web site.

Live Assist…

View original post 109 more words

{Dynamics 365 Portals} Set Password restrictions for User Registrations in Dynamics 365 portal

I have been working on Dynamics 365 portals (previously ADX portals) for some time now and recently I got a question on how to enforce Password restrictions during user self registration or redeeming invitation.

Well, although this feature is very easy to set-up but somehow difficult to find in the documentation. Hence thought of penning this blog

Suppose your requirement is to enforce the below password restrictions for your portal users.

  • Password must be more than 8 characters long
  • Should contain one lowercase and one uppercase at-least
  • should be alphanumeric

Thinking now that I would start writing lots of lines of code. Well its exactly the reverse.

Just got to CRM –> Portals –> Site Settings and then create few site settings records as shown in the below screenshots. If the site-settings are already present, do not re-create. Instead adjust their values accordingly.

For Requirement – Password must be more than 8 characters long create a site setting with the below information.

image

 

For Requirement – Should contain at-least one uppercase and one lower case letters.

image

 

image

 

For Requirement – Should be alphanumeric

image

 

All set and done. Just refresh the ADX portal and now when the user tries to register, gets an appropriate depending on the entered password.

 

image

image

 

Wonderful isn’t it?

Couple of settings which you might find useful

Authentication/UserManager/PasswordValidator/RequireDigit – Whether the password requires a numeric digit (‘0’ – ‘9’)

Authentication/UserManager/PasswordValidator/RequireNonLetterOrDigit – Whether the password requires a non-letter or digit character

 

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consulting/ training please contact at info@xrmforyou.com

Try our products at – http://www.xrmforyou.com/products.html