Posted in Calculated & Rollup Fields

How to get value from a lookup or parent entity using Calculated field in Microsoft Dynamics CRM

Did you ever need to get values from other entity or from a lookup on current entity? What comes to your mind, bet it is javascript , plugin etc?

Well, lets pause the coding life for minute and do it using Calculated Fields which used simple UI like business rules.

In Scenario below , i am retrieving the Budget Allocated amount from source campaign on a lead record.

  1. Create a currency Calculated field on lead record :1Give the appropriator name , select data type as Currency or as per your need > Select Field type as Calculated and click on Edit. As soon as you click on edit, system will actually create this field for you.
  2. After clicking on Edit button , you will be presented with the UI where you have put in  your logic:2

    As a first step i am checking if Budget Allocated field on campaign actually has data.To do this you have select Source campaign in the Entity and the corresponding field.

  3. Once this condition is set click on the Action :3

    In the editor start the typing the name of source campaign lookup or you can scroll though all fields/lookups available on the lead entity. Here i have select campaignid

  4. Once selected the campaignid , enter a dot(.) – post which you will start getting fields from the campaign:4

    Here i am selecting the budgetcost(Allocated Budget)

  5. Finally it will look like below :5Save and close the editor and also the field property window.
  6. Put this calculated field on the form and publish customization.
  7. Open a lead which has campaign associated to it:

    6campaign :

    7It is a very basic example i showed , i tried not to make it complex as it might become very confusing for a beginner.  You can do a lot manipulation with the data by using out of the box functions that are available for a calculated field or apply your custom logic.hope this helps!

    cheers!

Posted in CRM WebApi/Javascript, Uncategorized

How to set PartyList in Microsoft Dynamics CRM using Javascript

Let make it a smallest blog possible.

below code i have been using without any issue when it comes to setting a partylist or multi lookup in CRM. In the below code i am retrieving the contact id or the id of entity which is there in the regarding field & setting it on the “From” field.

function setCallFrom() 
{
 var lookup = new Array();
 lookup = Xrm.Page.getAttribute("regardingobjectid").getValue();
 if (lookup != null) {
 var name = lookup[0].name;
 var id = lookup[0].id;
 var entityType = lookup[0].entityType;
 if (entityType == "contact") {

var value = new Array();
 value[0] = new Object();
 value[0].id = id;
 value[0].name = name;
 value[0].entityType = "contact";

Xrm.Page.getAttribute("from").setValue(value);
 }

}
}

With slight modifications you can use the code on any other activity if you need to set partylist.

Call this function on Onload of the record or on onchange of the regarding field.

hope this helps!

Cheers!

Posted in Uncategorized

Show entity form based on a field value in Microsoft Dynamics CRM

Having multiple forms for an entity is definitely amazing since you can control visibility of fields without having to write business rule or Javascript to hide hundreds of fields based on some value.

Now out of the box you can control CRM forms visibility/preference using security roles. However it is not you would always want to to do; sometimes you might have to control form preferences based on field value.

here is the sample code that i am using – on load of create/update/all forms i am retrieving a value from owner of that record – since on creation only owner gets filled up.  I have create a field “new_form” as a whole number on system user :

1

i have currently have it a value as “2”. lets see how i am going to retrieve this value in my code and set the correct form :

//do a webapi action to retrieve the form value from systemuser.

var formnewvalue = ' ';
function retrieveFromValue() {
 debugger;
 var userid = Xrm.Page.getAttribute("ownerid").getValue();
 var newid = userid[0].id.slice(1, -1);
 var req = new XMLHttpRequest();
 req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/systemusers(" + newid + ")?$select=new_form", true);
 req.setRequestHeader("OData-MaxVersion", "4.0");
 req.setRequestHeader("OData-Version", "4.0");
 req.setRequestHeader("Accept", "application/json");
 req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
 req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
 req.onreadystatechange = function () {
 if (this.readyState === 4) {
 req.onreadystatechange = null;
 if (this.status === 200) {
 var result = JSON.parse(this.response);
 var new_form = result["new_form"];
 var new_form_formatted = result["new_form@OData.Community.Display.V1.FormattedValue"];
formnewvalue = new_form_formatted;

 showForm();

 } else {
 Xrm.Utility.alertDialog(this.statusText);
}
 }
 };
 req.send();
}
function showForm() {
 debugger;
var lblForm;
var relType = formnewvalue

switch (relType) {
case "1":
lblForm = "Portal Contact";
break;

case "2":
lblForm = "Profile Web Form";
break;

default:
lblForm = "Contact";

}
 //check if the current form is form need to be displayed based on the value
 if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) {
 var items = Xrm.Page.ui.formSelector.items.get();
 for (var i in items) {
 var item = items[i];
 var itemId = item.getId();
 var itemLabel = item.getLabel()
 if (itemLabel == lblForm) {
 //navigate to the form
 item.navigate();
 } 
 } 
 }
}

if you notice my switch statement you will see i m assigning the name of the forms to the values that i will be setting on the user profile.

Once it gets the form name – it than runs through all the forms for this entity untill it fins the correct form and then navigates to it.

i would say this script is majorly needed for first time or for a new system – since Internet Explorer or Chrome keep the form preference , so once our code the job and opened the required form -next time even if we remove the script -it will opening that form.

Another good is – this script prevents user to switch to other form as whenever  a user try to switch the form – on load event triggers and again check the value from owner id and change it back to the required one.

so since i have assigned value “2” to my user i should see “Profile Web Form” , lets see if this works :

2.jpg

woo , it did work.

point to note is you will have to attach this script to all the forms in the entity and call the function on onload for all forms.

hope this helps!

cheers!

Posted in Business Rules

Calculation Using Business Rules in Microsoft Dynamics CRM

Hi Guys,

We all love business rules & i am a big fan of them since they save alot of your time developing javascript for small actions that you need perform for e.g from making a field mandatory to setting fields value or showing error message.

Well , fortunately business rules can help if you need to perform some simple calculation on a form based on field values too. Lets get into action.

I have thought of a silly scenario where if i have estimated closed date on opportunity – i would like to set a date of 10 days before the estimated closed on a custom date field that i have created. Based on that i can then perform some other action using this new value either with JavaScript or business itself. This is dynamics crm 365 trial that i am using but its pretty much similar in 2016 or 2015.

So lets create a business role.

  1. Add a new condition to check if Est. Closed date contains data AND the new field(date difference) doesn’t not contains data.
    please note that if we don’t check the second condition the business rule will run every time and set the value to date difference on every on load even if date difference has been set last time :1
  2. Now once we are done with condition , lets add the action to it “set field value”. and from right side select the field = “date difference” , Type = “Formula”, other field = “Est Closed Date” , Operator = “-“, Type = “Value” , Days = “10”. Take a look at reference below:
    2
    3
  3.  now lets apply , save , Activate the business rule.
  4. Lets open a record a with estimated closed date and see it in action 🙂
    4
  5. the date difference field has been set to 10 days before the est close date which is 24-02-2017.
    5.PNG

There you go , it was simple example but i am sure you can perform some more complex calculation and not on just date fields but on currency and other fields.

Hope this helps!

Cheers!

Posted in CRM WebApi/Javascript, Uncategorized

Lock all fields on a form using Javascript- Microsoft Dynamics CRM

Hi Guys,

We all get requirements to lock the whole form to stop people from editing the record.

There are some out of the box options available to achieve this :

  1. Create a business rule : you can easily create a business and use lock field feature however you will have to select all the field on the form one by one – for .e.g if you have 50 fields on the form, you will have to add action for all of them. Moreover another limitation is if a field is removed from the form – you business rule will stop working.
  2. We all know if record is status is set to inactive – form become uneditable but in this scenarios we want to keep the record but uneditable.

Therefore, we come down to our final easy solution to tackle all problems above, the Javascript. Have a look on the below code :

 function disableFormFields()

{

       Xrm.Page.ui.controls.forEach(function (control, index) {

           var controlType = control.getControlType();

           if (controlType != “iframe” && controlType != “webresource” && controlType != “subgrid”)

           {

               control.setDisabled(true);

           }

       });

}

above code takes the control of the form directly rather then of each field & locks all of them. Just call the function on Onload , I have used this on my form and it looks like below:

lockfield

 

Now you can definitely add your own logic into this code for .e.g you put a if condition to check some value based on which you want to lock all fields and another things if you need to leave some fields unlocked you can again you a if condition , check the value and use below

just add the below code to above code :

if (crmfield = abc)

{

Xrm.Page.ui.controls.get(“CrmFieldShcemaname1”).setDisabled(false);

Xrm.Page.ui.controls.get(“CrmFieldShcemaNam2”).setDisabled(false);

Xrm.Page.ui.controls.get(“CrmFieldShcemaNam2”).setDisabled(false);

}

 

hope this helps you!

cheers

Posted in Uncategorized

How to insert dynamic values from custom entities in an email template – Microsoft Dynamics CRM

if you work with email templates; you might have to create a template which is to be sent from a custom entity & hence you will need field values from that entity.

Now out of the box – CRM doesn’t provide you an option to populate the field values from a custom entity.

So lets dig in and understand ; how this can be done.

1.Go to Templates from CRM settings and click on email templates ; click on “new” & in the popup select template as “Global”:

1

now if you notice – CRM gives you templates for individual entities as well but since we need one for custom entity – we will have to select global.

2. In the Template form, fill subject & Title.

2

3.In this example – i have a custom entity Loan, i would like to send email from this entity using an email template with Loan amount and customer populated. Customer is a lookup so lets do it.

Standard format is : {!EntityLogicalName:FieldLogicalName;}

for lookup values ; you would want to retrieve the name so you have to do it like below :

3

4. Hit save and it will be resolved:

4.png

5. now lets retrieve the loan amount which is a currency field:

5

6. Hit save and see the how this resolves as well:

6

if you have noticed – i have also inserted the current user name from out of the box feature “insert/update” from top button.

Similarly, you can do this with other fields like below :

single line of text : {!EntityLogicalName: FieldLogicalName; Default Text}

Date :  {!new_loan:new_approvaldate/@date;}
Time : {!new_loan:new_approvaldate/@time;}

Lookup : as we did above

Optionset : {!new_loan:new_loantype/@name;}

7. Now lets see our template in action ; i will go the loan entity record and insert a template:

7

Yay! it worked like a charm.

so , that is how it is done. Let me know if you face any difficulties.

Cheers!!

 

 

 

 

Posted in Uncategorized

Create a Gantt Chart in MS CRM

Nice blog by crm chart guy – made it look easy and simple.

crm chart guy

Until recently I thought that Gantt charts couldn’t be done in MS Dynamics CRM without turning to some serious development, which I found unfortunate because this is a popular type of chart and users find them easy to read. Turns out you can, and it’s not that difficult to create a simple Gantt Chart in MS CRM.

EDIT regarding CRM2011: This post relies on changing the aggregate of a date field to “min”, which seems to be exclusive for CRM2013. CRM2011 will give you an import error when you make that change to the xml. However, a reader has been kind enough to send me the details of how make it work for CRM2011. In the fetchxml you will need to remove the aggregate=”min” from each of the attributes, and also remove the groupby=”true” along with its corresponding alias in the categorycollection. Thank you Nils for sharing.

In this…

View original post 1,163 more words

Posted in Uncategorized

Run On-Demand Workflows on bulk records using XrmToolBox – bulk workflow execution

Microsoft Dynamics CRM On-Demand workflows are great and help in so many ways/

you can easily run these on records such as 100 , 500, 1000 & may be on 2000? But wait… how about 10000 records? thats where it might become very hectic but with introduction of a new plugin/tool in XrmToolBox – it has become very easy. – thanks to Andy Popkin 🙂

All you have to do is download XRM toolbox from the main website or github :

https://www.xrmtoolbox.com/

https://github.com/MscrmTools/XrmToolBox

Now once you have this tool and extracted – you might not have the bulk workflow execution tool in it. you will have to go to plugin store from the xrm tool and add it as belowpluginstore

once you go there it will give you hell lot of plugins you have to look for “bulk workflow execution” plugin and install it as below :

installplugin

once this is done you should be able to search this tool in your XRMtoolbox :

search&run

double click on it and get into action

  1. make sure your workflow is already is configured to run as ondemand
  2. all ondemand workflows in the organization will come under the dropdown i have highlighted.
  3. once you select the wofklow – it will give a list of all views from the entity which is a primary entity of the workflow. you can select the view and run your workflows on view returned records.
  4. you can also define your own custom fetch XML query ; which we will do now.

1

here i am using the below fetch XML as an example :

<fetch distinct=”false” mapping=”logical” output-format=”xml-platform” version=”1.0″ >

<entity name=”task” >

<attribute name=”subject” />

<filter type=”and” >

<condition attribute=”scheduledend” operator=”null” />

<condition attribute=”statecode” operator=”eq” value=”0″ />

<condition attribute=”createdon” operator=”on-or-before” value=”2017-12-15″ />

</filter>

</entity>

</fetch>

2

you can click on validate to validate your query ; once your query is confirmed you will have run workflow button enabled next to it and also will show how much record it has retrieved. click on the run workflow button and see the action :

3

it will work like a charm and will definitely save alot of your time.

i will be sharing more cool add-on in XrmToolBox because i am a fan of this tool ; so stay tuned.

 

cheers!

 

 

Posted in Uncategorized

Escape from waiting condition workflows – Microsoft Dynamics CRM

Waiting condition workflows are definitely great and almost perfect for the functionality where you have to wait for months for something to be triggered.

but are they really good ; should actually keeping them alive for months is a good idea? Well there are certain measures that you can take if you really need them :

  • Combine waits and check condition. So you have a process that emails a customer service representative three days after the case is open. No need to email them if the case has been closed, right? After the wait, have the workflow check conditions to verify that the condition that triggered the workflow is still true. If not, cancel , but stop it.
  • Use a child workflow to do something when wait time is over.
  • Use short wait periods. 20  minute waits are ok. 1 year waits are bad.
  • Use timeouts rather then wait condition.

 

however apart from the above there is another way which can be effective in terms of your organization performance.

Create an entity to keep the crucial date or timestamps on which you want to do something.

  1. create an entity(workflow task) , with fields as “regarding” & “Due date”.
  2. In your workflow – if you need to do something for example 20 days before the expiration date – calculate that date and create a a new record for the entity created(workflow task) with regarding as the current record and the date in due date field.
  3. Stop your workflow – just end it right there.
  4. Create a bulk delete job -that you should run everyday which checks for the records who’s due date is today and delete them.
  5. Create a workflow on the new entity created(workflow task) – run it on deletion of the record and do the actual things you wanted to on your record from that workflow for example closing the activity , sending email etc.

 

Best thing about this approach this that you can continue using this logic in your organization with n number of records & entities.

 

let me know your thoughts on this.

Cheers !

Posted in Certifications

Sample Questions & Tips for Exam MB2-713: Microsoft Dynamics CRM 2016 Sales

It is the most difficult and interesting crm certification i have come across.

i am going to give you some tips and sample questions that you can expect.

  1. understand the CRM sales process : https://crmbook.powerobjects.com/basics/microsoft-dynamics-365-sales-process/
  2. guidance from a champion : https://neilparkhurst.com/2016/03/28/mb2-713-certification-microsoft-dynamics-crm-2016-sales/
  3. finally some sample questions:

1.Your Dynamics CRM organization uses Microsoft Yammer.
You plan in enable integration with Yammer to replace the default CRM activity feeds.
You need to identify which security rights are required to enable the integration.
Which two security rights should you identify? Each correct answer presents part of the solution.
A. Dynamics CRM administrator
B. Dynamics CRM System Customizer
C. Yammer administrator
D. Microsoft SharePoint administrator
E. Microsoft Office 365 administrator

Answer :AC

2. You Open the My Open Opportunities view,
You need to export the data in the view, and then to reimport the data so that the existing records are
updated.
What should you do?
A. Export the data as a dynamic Pivot Fable.
B. Export the data as a Static worksheet.
C. Export the data and select the Make available for re-import option.
D. Export the data as a dynamic worksheet

Answer : B

3.You have a recalled product that should no longer be sold.
You need to remove the. Product from the available list of products and to prevent any sales from being
processed for the product.
Which two actions should you perform? Each correct answer presents part of the solution.
A. Remove the product from the family hierarchy.
B. Modify the open opportunities.
C. Update the price list.
D. Retire the product.
E. Modify the validity date of the product.

Answer:BD

4.You have an existing customer named customer1.
You have a new add-on product for an existing product that you sell.
You want to offer the add-on product to a customer who has purchased the existing product already.
You need to track the sales initiative in Dynamics CRM.
What should you do?
A. Update the original opportunity record.
B. Create a new opportunity record for the new offering.
C. Create a sub-account for the new offering.
D. Reopen the original opportunity record.

Answer : B

5.Your marketing team is promoting a sale that they will announce by using email. The email message will
be sent to existing customers who recently purchased similar products and to potential customers from
a purchased mailing list.
Any sales made as a result of the sale need to have the pricing applied, the sales must be tracked so that
the marketing team can report on the return on investment (ROl) of the initiative.
What are two possible ways to achieve the goal? Each correct answer presents a complete solution.
A. Convert the email activities to leads.
B. Convert the campaign response activities to opportunities.
C. Convert the campaign response activities to leads.
D. Convert the email activities to opportunities.

Answer : BD

6.You have a Dynamics CRM organization that has several currencies enabled. What occurs when a user
creates a record that has a currency field?
A. The currency is based on the sales territory of the user.
B. The currency is based on the location of the user record.
C. The currency is converted into the base currency and is always displayed in the base currency
D. The system default currency is the record default, unless a customer has a default currency

Answer : D

7.You company employs consultants who bill customers for their time.
You sales team is responsible for selling the consultants time, in addition to selling product licenses.
You need to provide the sales team with the ability to create opportunities, quotes, and invoices for the
consultant’s time.
What should you create first?
A. a product family
B. a price list
C. a product bundle
D. a unit group

Answer 😀

8.Your company plans to deploy Dynamics CRM.
In the previous sales database, you did not track products
Members of the management team are evaluating whether to use the product catalog in the CRM
organization. You need to identify which enhancements to the sales flow can be achieved by using the
product catalog. What are two possible enhancements that you can identity? Each correct answer
presents a complete solution.
A. inventory management integration
B. automated sales pipeline velocity tracking
C. automated revenue calculation
D. automated quotes, orders, and invoicing

Answer :CD

9.Your company has a Dynamics CRM organization.
The company plans to use the product catalog.
You need to identify which component must be configured before you can implement the product
catalog.
A. product families

B. product
C. price lists
D. unit groups

 

Answer : D

10.You need to identify which type of object can be associated to sales territories. Which type of object
should you identify?
A. Opportunities
B. Users
C. Leads
D. Facilities
E. Teams

Answer : B

 

Hope this helps

you can write to me @ rawish_kumar93@hotmail.com if you need any support.

Cheers!