Tuesday, October 20, 2020

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, Address Line3, City, Country and Zip code. your requirement to put this address like below.

Address Line1

Address Line2

Address Line3

City, Country

Zip Code

Now suppose Address Line2 is empty in that case it will show the 2 line space between Address Line1 and Address Line3.

To remove this space inside the flow we will use the split function, suppose your string variable having the value like- AddVar = Address Line1,Address Line2,Address Line3,City, Country,Zip Code

Now you use an "Apply for each" for this variable and traverse the values and finally append into another string variable "VarActualAddress".

To Split values use the expression split(Addvar,','), then check the Current value empty condition and finally append the current value into another variable "VarActualAddress"

For your reference follow the below image.




Monday, October 19, 2020

Retrieving All Records owned by other Team Members

 Many times there is a requirement to retrieve all the records of team members where you are a member in those teams. To get them setup the filter as given in image.



Wednesday, September 2, 2020

Insert New Line in to a String in Power Automate or Flow

 Many times we have gone through with the requirement like to enter address in word document but if the address present into a multipline textbox in CRM then it will be visible as is. To solve this problem we required to insert the address in Multiline textbox in CRM using New Line character, but it is bit dificult to enter it through the Microsoft flow.

Below is the text and the image which need to be inserted in place of "\n".

Text is : json('{"NL":"\n"}')?['NL']

you can utilize it like the image given below.




Monday, August 31, 2020

Timer or Timer Control in JavaScript with Start, Stop and Pause button

I gone through one of the Timer requirement in my project on case entity in D365 CRM, to achieve this we will use the below code in HTML web resource and then insert the web resource in entity form.

Below is the Image of this timer web resource.

Java Script code with HTML buttons:
<!DOCTYPE html>
<html>
<head>
<script>
var t;
var runningtime;
var sstime;
var tsec=0;
function startTime() {
  //document.getElementById('btnstop').disabled =false;
  //ocument.getElementById('btnpause').disabled =false;
  var d = new Date();
  var year=d.getYear();
  var month = d.getMonth();
  var day = d.getDay();
  var hours=d.getHours(); 
  var minutes=d.getMinutes(); 
  var seconds=d.getSeconds(); 
  var milliseconds=d.getMilliseconds();
  var today = new Date(year, month, day, hours, minutes, seconds, milliseconds);
      
  if(document.getElementById('sttime').innerHTML=='')
  {document.getElementById('sttime').innerHTML =today;
  sstime=today;}
  var h = today.getHours();
  var m = today.getMinutes();
  var s = today.getSeconds();
  m = checkTime(m);
  s = checkTime(s);
  runningtime=new Date(today);
  document.getElementById('txt').innerHTML =
  h + ":" + m + ":" + s;  
  t = setTimeout(startTime, 500);
}

function checkTime(i) {
  if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
  return i;
}
function calulatetime()
{
document.getElementById('sttime').innerHTML='';
var ttime= date_diff_inminutes(runningtime,sstime);
document.getElementById('totime').innerHTML =ttime;
tsec= date_diff_inseconds(runningtime,sstime) + tsec;
document.getElementById('tosec').innerHTML =tsec;
document.getElementById('btnpause').disabled =true;
//document.getElementById('btnstart').disabled =false;
document.getElementById('btnstop').disabled =true;
var tothour=document.getElementById('tosec').innerHTML/3600;
//var tothour=Math.floor(document.getElementById('tosec').innerHTML/3600);
//var tothour1=Math.ceil(document.getElementById('tosec').innerHTML/3600);
//alert("total hours spend " + tothour);
//alert("total hours spend " + tothour1);
alert("total hours spend " + tothour.toPrecision(6));
}

function calulatetimeinsec()
{
tsec= date_diff_inseconds(runningtime,sstime) + tsec;
document.getElementById('tosec').innerHTML =tsec;
document.getElementById('sttime').innerHTML='';
}

var date_diff_inseconds = function diff_seconds(dt2, dt1) 
 {
  var diff =(dt2.getTime() - dt1.getTime());  
  var seconds = Math.floor((diff % (1000 * 60)) / 1000);

  // Display the result in the element with id="demo"
  return seconds;  
 }
 
var date_diff_inminutes = function diff_minutes(dt2, dt1) 
 {
 var diff =(dt2.getTime() - dt1.getTime());
  /*var diff =(dt2.getTime() - dt1.getTime()) / 1000;
  diff /= 60;
  return Math.abs(Math.round(diff));  */
  
  
  // Time calculations for days, hours, minutes and seconds
  var days = Math.floor(diff / (1000 * 60 * 60 * 24));
  var hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((diff % (1000 * 60)) / 1000);

  // Display the result in the element with id="demo"
  return days + "d " + hours + "h "  + minutes + "m " + seconds + "s ";
  
 }
 
var date_diff_indays = function(date1, date2) {
dt1 = new Date(date1);
alert(dt1);
dt2 = new Date(date2);
alert(dt2);
return Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate()) - Date.UTC(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()) ) /(1000 * 60 * 60 * 24));
}
</script>
</head>

<body>
<button id="btnstart" onclick="startTime()">Start</button>
<button id="btnstop" onclick="clearTimeout(t);calulatetime();">Stop</button>
<button id="btnpause" onclick="clearTimeout(t);calulatetimeinsec();">Pause</button>
<div id="txt"></div>
<div id="sttime"></div>
<div id="totime"></div>
<div id="tosec"></div>

</body>
</html>




Steps to Start, build and create a PCF Control from Scratch

 Following are the high level steps to start and create a PCF control using Visual Studio 2017.

This is devided into three parts:-

1. Install the required software/Components

  • Install npm
  • Install PowerApps CLI
  • Install Visual Studio 2017 or later

2. Create a PCF Control

  • Create a new folder for the project.
  • Open Developer Command Prompt and Navigate the pointer to the folder created above.
  • Run the following command
  • pac pcf init --namespace <specify your namespace here> --name <Name of the code component> --template <component type
  • Install the project dependencies using command (npm install) 
  • Update ControlManifest.Input.xml
  • Update index.ts
  • Build the project using (npm run build)
  • Start the Component (npm Start)
  • Create a folder for holding the solution zip and related files. Navigate to that folder and run the command. (pac solution init --publisher-name HKPublisher --publisher-prefix hk)
  • Add reference of the custom component in the solution (pac solution add-reference --path ../    ** Path of SolutionPackage Folder)
  • To create the Solution Zip File (msbuild /t:build /restore)

3. Import the Solution into your CRM Instance 

  • Import the solution file and use it inside Dynamics 365 CE


 


Friday, July 17, 2015

CRM 2013 Subgrid vs. (Expanded) Associated View Records. OR Recent and Associated Entity views

Sometimes you experienced when you have subgrid in your CRM Form, but when you click the ‘expand’ button to expand the view then it will redirect you to Associated View, but you found the records appear in the list are different.

to find the solution of that problem then click the below link or directly read the same content from my blog.

https://community.dynamics.com/crm/f/117/t/141127

http://missdynamicscrm.blogspot.se/2014/10/crm-2013-subgrid-vs-expanded-associated-view-records.html

I have checked this issue.

So, the issue will be happening if you have one more Opportunity to Account custom N:1 Relationship.
For example:
The standard CRM have 2 normal N1 Relationship to Account, those are Parent Account and Potential Customer.
Then, I added one more relationship with name new_account2 (Account 2) as shown here:


If you notice, in the subgrid, the Entity (Opportunity) is having setting:
(see the section inside the red-square)

So, it means that only show if the Potential Customer is the respective account, correct.
Then if you click to pop out the associated view, some of your Opportunities are gone and missed out to appear in the list.
After I checked, it was because the missed Opportunities didn't have relationship to the new relationship (in this case is new_account2 or Account 2)
So, I put more detail here.
Now, in the Account, I have two Relationship to Opportunity in the Navigation explorer.

The first one is Account to Opportunity (Custom)

The second one is Account to Opportunity (System)

And if I go to each Associated View, it will give me different result.
Okay, this is from the subgrid:

*You can see 2 Opportunities, correct.
Then, try again to see the Associated View from the Navigation.
This is from the first one (a custom relationship)

*Yes, you can only see 1 Opportunity
And this is the second one (a system relationship)

* You can see two records of opportunity and see the arrow, the new section of filter, showing it is a different associated view
And finally, from the pop out from the Recent Opportunities subgrid.

*As you can see, you can only see one (1) record, so this view, after you pop up out is referring to the custom relationship (to Account 2)
To check deeper, I try to search in the database what is the different between them, and then, yes it is actually because of the disappeared opportunity does not have relationship to Account 2:

*See the null value of Account 2, the rests are same.
And I guess, the missing Opportunities are the existing Opportunities just before you created a new custom relationship.
Because basically, for the new records, CRM will auto populate and auto-mapping all of the lookup relationship to the same entity if newly created from subgrid or associated view., in this case is Account, but not for old records (CRM Mapping behavior concept).
To ensure you and myself, I put the Account fields in to the Opportunity Form.
All of the account fields

and

And you can see that one of them doesn't have value for the Account 2, and the Opportunity with the null value will not show in the Associated View.
To check in your data, you see the missing Opportunities in your data, there are 2 records, which one them is:
"Leslie Test Lead 0627-16", and the other one I can't see since this is not in the first page.
You can try to go to Associated View and then 'Add Existing Opportunity', then add the "Leslie Test Lead 0627-16", now back to your Opportunity Form.

Then,

After that you open the form..

Now, you can see that the custom field to custom Account, in my term is Account 2, now is filled up!.
I guess this is the answer.
SO, back to your question.
How the views are populated?
The answer is:
- For the Recent Opportunities shown in the subgrid, it shows all of the related Opportunity record from the Potential Customer.
- For the Associated View pop out from the subgrid, it shows all of the related Opportunity record from the new custom relationship.
And in fact, it picks the first relationship defined in the navigation in order or in sequence (see the solution in the below section for detail)
How to solve, there are two solutions basically.
1. You fix the data, fill the value of your new custom relationship (you can use Account 2 field in the Opportunity Form) or can use by adding the Existing Opportunity through the Opportunity Associated View in the Account form, as for this example: "Leslie Test Lead 0627-16".
Or you can use Workflow or programming to auto-fill the Account 2 aligning with the Potential Customer value.
2. You can use either: Remove the Navigation of the Custom relationship
OR, just Re-Order the position of those relationship in the navigation area:

So, now this is the result after you re-order, the subgrid after you click the pop up will no longer calling the wrong associated view, instead, it will call the associated view by Potential Customer (since you put it first)

Now, your customer will see the same for subgrid or associated view after clicking the 'grid' ribbon to show the detailed associated view. And they will not frustrate again.
 

Filtered lookup for Dynamics CRM 2013

Filtered lookup is a feature which was introduced in Dynamics CRM 2011, a greatly appreciated improvement from CRM 4. Prior to this, developers had to use third party tools to achieve the same result.
So, let’s start at the very beginning

What is filtered lookup?

When you have a large data set, and you want to filter the data in a progressive manner, then you need filtered lookup. You select one criteria/field and the data is filtered as per that. Now, if you choose the next field, then this filter is further applied to the already filtered data so as to give your further specific results.
For example: You have a list of prospective sales leads, and you want to filter out prior to a campaign based on those who are doctors and those who are in the state of Massachusetts. For this data selection, you would require a filtered lookup, so that the state/ profession is first selected and then following which on choosing the second criteria, the filter should be applied to the already once filtered data.

Now, let us write the code to achieve this.
This piece of code is very small as compared to what we used to write to achieve the same result in CRM 2011.

function preFilterLookup() {
debugger;
Xrm.Page.getControl("new_linkedaccount").addPreSearch(function () {
addLookupFilter();
});
}
function addLookupFilter() {
var fetchXml = '';
Xrm.Page.getControl("new_linkedaccount").addCustomFilter(fetchXml);
}
 
NOTE:
1. addLookupFilter function can only be called from addPreSearch function that binds the function to the Lookup Control. Although, you can provide any filter condition in the fetchxml form (which you can get using advanced find) to see the filtered records.
2. Two parameters ‘filter’ and ‘entityLogicalName’ are what the addCustomFilter method will accept. If the entityLogicalName is provided (not mandatory), the filter will only be applied to that entity type, else it will be applied to all types of entities returned.

For CRM 2013 Using addCustomFilter() to get Filtered Lookup Field based on Linked Entity

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...