Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

10 December 2014

Quickly view schema name and guid in crm form

Most of the time we need to refer to our CRM entity/ form for schema name during development.
Here is some script which can allow developer to identify via the CRM record form.

Create a file with following code, save as Debug.url extension, so you can use this as shortcut in bookmark to trigger the script.  Just copy to Favorite folder, it is ready to use.



[DEFAULT]
BASEURL=http://mscrm:5555/DEV/main.aspx
[DOC_contentIFrame]
BASEURL=http://mscrm:5555/DEV/_root/homepage.aspx
ORIGURL=/DEV/_root/homepage.aspx
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,15
[InternetShortcut]
URL=javascript:(function(){javascript:var x = 0; while (frames[x].Xrm.Page.data == null) {x++;} frames[x].Xrm.Page.ui.tabs.forEach(function(b){b.setVisible(true);b.sections.forEach(function(c){c.setVisible(true);})}); frames[x].Xrm.Page.ui.controls.forEach(function(a){a.setVisible(true); if (a.setDisabled != null) {a.setDisabled(false);} var span = document.createElement('span'); span.innerHTML = ''; if (frames[x].document.getElementById(a.getName() + '_c') != null) {frames[x].document.getElementById(a.getName() + '_c').appendChild(span);}}); var span = document.createElement('span'); span.innerHTML = ''; frames[x].document.getElementById("form_title_div").getElementsByTagName("div")[0].appendChild(span); var span = document.createElement('span'); span.innerHTML = ''; frames[x].document.getElementById("form_title_div").getElementsByTagName("div")[0].appendChild(span);})();
IDList=
IconFile=http://mscrm:5555/favicon.ico
IconIndex=1
HotKey=0
[Bookmarklet]
ExtendedURL=javascript:(function(){javascript:var x = 0; while (frames[x].Xrm.Page.data == null) {x++;} frames[x].Xrm.Page.ui.tabs.forEach(function(b){b.setVisible(true);b.sections.forEach(function(c){c.setVisible(true);})}); frames[x].Xrm.Page.ui.controls.forEach(function(a){a.setVisible(true); if (a.setDisabled != null) {a.setDisabled(false);} var span = document.createElement('span'); span.innerHTML = ''; if (frames[x].document.getElementById(a.getName() + '_c') != null) {frames[x].document.getElementById(a.getName() + '_c').appendChild(span);}}); var span = document.createElement('span'); span.innerHTML = ''; frames[x].document.getElementById("form_title_div").getElementsByTagName("div")[0].appendChild(span); var span = document.createElement('span'); span.innerHTML = ''; frames[x].document.getElementById("form_title_div").getElementsByTagName("div")[0].appendChild(span);})();

11 February 2009

Prompt Backdated Disallowed on CRM datetime field

CRM 4 date time control manage to minimize the error on user input by allow them to select a date from drop down calendar. Now, real word business scenario might required more advance of date time validation on date time field input.

Given scenario: Follow Up Date must be greater or equal to today.
The most easiest way to achieve the requirement is by Javascript; let see how it works
every time user change the field, onchange event on CRM fire the javascript to verify the input.

 <br />
function FollowUpDate() <br />
{ <br />
var current=new Date(crmForm.all.createdon.DataValue); <br />
var days=-1; //To handle crmForm onCreate or onChange <br />
if(crmForm.all.createdon.DataValue==null) <br />
{ <br />
d=new Date(); <br />
current.setFullYear(d.getYear(),d.getMonth(),d.getDate()); <br />
days=0; <br />
} <br />
<br />
var selected=new Date (crmForm.all.followupby.DataValue); <br />
<br />
var ONE_DAY=1000*60*60*24; <br />
var different=selected-current; <br />
var indicator=Math.round(different/ONE_DAY);  <br />
<br />
if(indicator<days){  
alert("Backdated disallowed for 'Follow Up By'."); 
crmForm.all.followupby.DataValue=null; 
}  
} 

Hope this simple javascript can help :)

24 August 2008

Reload/Refresh parent window from pop up window (dialog window)

Let say you have a parent window with some information loaded from database, and then you have a link that will prompt a new dialog window base on the selection item on parent window. After you finished editing the data in dialog window, you click save then close. BUT… at the same time you also want parent window to auto refresh in order to show the realtime information/changes you have made. You can achieve this by many methods; AJAX..javascript..codebehind.. In my opinion, I think javascript is the easiest way to achive this. Just fire this javascript function on your dialog window’s close button. Thats all you need to do Just give me a thumb if really help you.
function ReloadParentWindow()
{
if (window.opener && !window.opener.closed)
{
window.opener.location.reload();
self.close();
}
}