Category Archives: JS Script

Creating RSS Feed Dashboard in Microsoft Dynamics CRM 2013: Part 3

This is our last post to create a RSS feed dashboard in Microsoft Dynamics CRM 2013. Please check our previous posts to create a RSS feed web resource for Microsoft Dynamics CRM Team blog and Twitter user account. In this post we will use these web resources in our dashboard.

Please follow our previous post to get RSS feeds and create web resources for the following URLs.

Once we have all the web resources ready, use the following procedure to create a RSS feed dashboard:

  • Navigate to Settings |Customization | Customize the System.
  • Navigate to Components | Dashboard | New.
  • Select “2-Column Regular Dashboard” from the layout and click on Create.
  • Fill in “Microsoft Dynamics CRM RSS Feeds” under the name TextBox.
  • Please your web resources in the dashboard columns and provide a display name.
  • After placing the web resources it should look like the following screen.

dashboard

  • Save your dashboard and navigate to the Microsoft Dynamics CRM 2013 home page.
  • Select Microsoft Dynamics CRM RSS Feeds dashboard from the drop down.

Our dashboard will look like the following:

firnaldashboard

Stay tuned for our next article.

HIMBAP | Need any help in Microsoft CRM 2013 Contact US !!

2 Comments

Filed under JS Script, MS CRM 2013

Show Loading message during function execution in CRM Form

I found one question in CRM Development form where user asked to show some processing message during long function execution, we have done this in many projects, so I thought to write this post so that it can be help CRM developers. if you are doing some processing or calling any webservice which is taking time to execute and you want to show loading messsage to user you can use below function

function showLoadingMessage() {
    tdAreas.style.display = ‘none’;
    var newdiv = document.createElement(‘div’);
    newdiv.setAttribute(‘id’, “msgDiv”);
    newdiv.valign = “middle”;
    newdiv.align = “center”;
    var divInnerHTML = “<table height=’100%’ width=’100%’ style=’cursor:wait’>”;
    divInnerHTML += “<tr>”;
    divInnerHTML += “<td valign=’middle’ align=’center’>”;
    divInnerHTML += “<img alt=” src=’/_imgs/AdvFind/progress.gif’/>”;
    divInnerHTML += “<div/><b>Working…</b>”;
    divInnerHTML += “</td></tr></table>”;
    newdiv.innerHTML = divInnerHTML;
    newdiv.style.background = ‘#FFFFFF’;
    newdiv.style.fontSize = “15px”;
    newdiv.style.zIndex = “1010”;
    newdiv.style.width = document.body.clientWidth;
    newdiv.style.height = document.body.clientHeight;
    newdiv.style.position = ‘absolute’;
    document.body.insertBefore(newdiv, document.body.firstChild);
    document.all.msgDiv.style.visibility = ‘visible’;
}

it will display message like below

once processing is done you can hide this message using below code

document.all.msgDiv.style.visibility = ‘hidden’;

Enjoy !!!

 

3 Comments

Filed under JS Script, MS CRM 2011, MS CRM 4.0

Get Max value using Javascript

 If you want to fetch Max value from CRM entity record using Javascript, you can use below code, remember to change entity and field name accordingly

var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.

var xml = “<?xml version=’1.0′ encoding=’utf-8′?>”+

“<soap:Envelope xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/'”+

” xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance'”+

” xmlns:xsd=’http://www.w3.org/2001/XMLSchema’>”+

authenticationHeader+

“<soap:Body>”+

“<RetrieveMultiple xmlns=’http://schemas.microsoft.com/crm/2007/WebServices’>”+

“<query xmlns:q1=’http://schemas.microsoft.com/crm/2006/Query'”+

” xsi:type=’q1:QueryExpression’>”+

“<q1:EntityName>EntityName</q1:EntityName>”+ //change entity name

“<q1:ColumnSet xsi:type=’q1:ColumnSet’>”+

“<q1:Attributes>”+

“<q1:Attribute>FieldName</q1:Attribute>”+ //change field name

“</q1:Attributes>”+

“</q1:ColumnSet>”+

“<q1:Orders>” +

“<q1:Order>” +

“<q1:AttributeName>FieldName</q1:AttributeName>” + //change field name

“<q1:OrderType>Descending</q1:OrderType>” +

“</q1:Order>” +

“</q1:Orders>” +

“</query>”+

“</RetrieveMultiple>”+

“</soap:Body>”+

“</soap:Envelope>”;

// Prepare the xmlHttpObject and send the request.

var xHReq = new ActiveXObject(“Msxml2.XMLHTTP”);

xHReq.Open(“POST”, “/mscrmservices/2007/CrmService.asmx”, false);

xHReq.setRequestHeader(“SOAPAction”,”http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple&#8221;);

xHReq.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);

xHReq.setRequestHeader(“Content-Length”, xml.length);

xHReq.send(xml);

// Capture the result.

var resultXml = xHReq.responseXML;

// Check for errors.

var errorCount = resultXml.selectNodes(‘//error’).length;

if (errorCount != 0)

{

var msg = resultXml.selectSingleNode(‘//description’).nodeTypedValue;

alert(msg);

}

else

{

var results = resultXml.getElementsByTagName(‘BusinessEntity’);

var msg = “”;

if (results.length == 0)

{

alert(msg);

return;

}

else

{

if(results[0].selectSingleNode(‘./q1:FieldName’)!=null)

{

var MaxValue = results[0].selectSingleNode(‘./q1:FieldName’).nodeTypedValue;   //change name of the field to get Max value

alert(MaxValue);

}

}}

Leave a comment

Filed under JS Script, MS CRM & Javascript

Run exe from MS CRM 4.0

If you are looking to run .exe from MS CRM 4.0, then you can do this easily. You can create a ISV button on MS CRM form and create on global function on formonload can call it in ISV button JS.. you can write below code to run .exe

var _Object=new ActiveXObject( “WScript.Shell” ) ;
_Object.Run(“C:\\WINDOWS\\system32\\calc.exe” );

 you can also pass parameters with Run command.

Enjoy !!!

4 Comments

Filed under JS Script, MS CRM 4.0

Close Activity Event in MS CRM

sometime we need to perform some action when activity is closed in MS CRM.In that case you have to capture close activity event, you can do this using event.Mode property in onsave event. you just have to write below code.

if(event.Mode==5) //Close activity event

{

//you code to implement your logic

}

Enjoy !!!

Leave a comment

Filed under JS Script, MS CRM & Javascript, MS CRM 4.0

Attach onclick event with MS CRM CRM checkbox

As you know that we can set control formatting of bit field to use it as checkbox. But only changing formatting does not make it to behave like a checkbox because of onchange event. Let take an example for this, like we have one field “Calculate Value” and we want to calculate some value on the selection of this bit field. We can set control formatting for the bit field to display like a checkbox.

 So if we will write some code onchange event of this bit field

alert(‘Clicked’);

You will not get this alert until you will move focus from this field. so make it to behave like real checkbox you have to attach onclick event with this field. You can do this using below code on form onload

crmForm.all.new_calculatevalue.onclick=function()

{

alert(‘Clicked’);

 }

after that you can simple check DataValue for bit ,if it is true or false to work accordingly

 Enjoy!!

1 Comment

Filed under JS Script, MS CRM 4.0

Remove Picklist option based on Security Roles

Most of the client asks for this requirement. They want to hide picklist options based on security roles. Let’s take an example for this, for example if we have picklist “Customer Status” having four option like “Request for Approve”,”Approved”,”Rejected”,”Black Listed”. Let’s say we have requirement to show only first option to all users having security roles other then “System Admin”. Only “System Admin” should be able to see all of these options, you can implement this using below code

//First check user have “sys admin” role or not

function CheckSecurityRole() {

    var xml = “” +

    “<?xml version=\”1.0\” encoding=\”utf-8\”?>” +

    “<soap:Envelope xmlns:soap=\”http://schemas.xmlsoap.org/soap/envelope/\” xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance\” xmlns:xsd=\”http://www.w3.org/2001/XMLSchema\”>” +

    GenerateAuthenticationHeader() +

    ” <soap:Body>” +

    ” <RetrieveMultiple xmlns=\”http://schemas.microsoft.com/crm/2007/WebServices\”>” +

    ” <query xmlns:q1=\”http://schemas.microsoft.com/crm/2006/Query\” xsi:type=\”q1:QueryExpression\”>” +

    ” <q1:EntityName>role</q1:EntityName>” +

    ” <q1:ColumnSet xsi:type=\”q1:ColumnSet\”>” +

    ” <q1:Attributes>” +

    ” <q1:Attribute>name</q1:Attribute>” +

    ” </q1:Attributes>” +

    ” </q1:ColumnSet>” +

    ” <q1:Distinct>false</q1:Distinct>” +

    ” <q1:LinkEntities>” +

    ” <q1:LinkEntity>” +

    ” <q1:LinkFromAttributeName>roleid</q1:LinkFromAttributeName>” +

    ” <q1:LinkFromEntityName>role</q1:LinkFromEntityName>” +

    ” <q1:LinkToEntityName>systemuserroles</q1:LinkToEntityName>” +

    ” <q1:LinkToAttributeName>roleid</q1:LinkToAttributeName>” +

    ” <q1:JoinOperator>Inner</q1:JoinOperator>” +

    ” <q1:LinkEntities>” +

    ” <q1:LinkEntity>” +

    ” <q1:LinkFromAttributeName>systemuserid</q1:LinkFromAttributeName>” +

    ” <q1:LinkFromEntityName>systemuserroles</q1:LinkFromEntityName>” +

    ” <q1:LinkToEntityName>systemuser</q1:LinkToEntityName>” +

    ” <q1:LinkToAttributeName>systemuserid</q1:LinkToAttributeName>” +

    ” <q1:JoinOperator>Inner</q1:JoinOperator>” +

    ” <q1:LinkCriteria>” +

    ” <q1:FilterOperator>And</q1:FilterOperator>” +

    ” <q1:Conditions>” +

    ” <q1:Condition>” +

    ” <q1:AttributeName>systemuserid</q1:AttributeName>” +

    ” <q1:Operator>EqualUserId</q1:Operator>” +

    ” </q1:Condition>” +

    ” </q1:Conditions>” +

    ” </q1:LinkCriteria>” +

    ” </q1:LinkEntity>” +

    ” </q1:LinkEntities>” +

    ” </q1:LinkEntity>” +

    ” </q1:LinkEntities>” +

    ” </query>” +

    ” </RetrieveMultiple>” +

    ” </soap:Body>” +

    “</soap:Envelope>” +

    “”;

    var xmlHttpRequest = new ActiveXObject(“Msxml2.XMLHTTP”);

    xmlHttpRequest.Open(“POST”, “/mscrmservices/2007/CrmService.asmx”, false);

    xmlHttpRequest.setRequestHeader(“SOAPAction”, ” http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple&#8221;);

    xmlHttpRequest.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);

    xmlHttpRequest.setRequestHeader(“Content-Length”, xml.length);

    xmlHttpRequest.send(xml);

    var resultXml = xmlHttpRequest.responseXML;

    if (resultXml != null) {

        //select the node text

        var RoleResponse = resultXml.selectNodes(“//BusinessEntity/q1:name”);

        if (RoleResponse != null) {

            for (i = 0; i < RoleResponse.length; i++) {

                if (RoleResponse[i].text == ‘System Administrator’) {

                    return true;

                }

            }

        }

    }

    return false;

}

//if your does not have sys admin role remove picklist options

//Let consider I have used index 1,2,3,4 for our picklist options

function HidePicklistOptions()

{

    If(!CheckSecurityRole())

    {

    var Picklist=crmForm.all.new_customerstatus; // get picklist

    Picklist.DeleteOption(2); //use approval index to remove Approved from piclist

    Picklist.DeleteOption(3); //to remove Rejected

    Picklist.DeleteOption(4); //to remove Black Listed

    }

}

 DeleteOption basically removes picklist option temporary, it does not remove them from database permanently.

Enjoy !!!

Leave a comment

Filed under JS Script, MS CRM 4.0

Format Left Navigation Item

Today I found one question in MS CRM Development Forum to format Left navigation item, we can easily do this with JS. Just use below code on form load. I have tested this in contact form to form “More Addresses”

var Item=document.getElementById(‘navAddresses’);

if(Item!=null){
Item.style.fontWeight = ‘bold’;
Item.style.color = ‘#ff0000’;}

and result will be  as below

Leave a comment

Filed under JS Script, MS CRM 4.0

Show Associated View in IFrame MS CRM 4.0

Some time we need to show associated view (1:N or N:N) in Iframe. I found a good article in https://community.dynamics.com/blogs/crmjimwang/comments/28067.aspx written by Jim Wang. After doing some little changes it worked like a charm for me. You can use this code for any associated view (1:N or N:N). You just need to get Left navigation item name that you can get through IE developer toolbar or Developer tools if you are using IE 8.

//Remember to change IFRAME_Name with name of iframe in your form.

//Check Form Type if it’s 1 than hide iframe.

if (crmForm.FormType == 1) {

//To hide iframe

    crmForm.all.IFRAME_Name.parentNode.style.display = ‘none’;

    crmForm.all.IFRAME_Name.parentNode.parentNode.style.display = ‘none’;

}

else {

    //Display associated view in Iframe

    var navId = “LeftNavigationItemName“; //Remember to replace this with left navigation item name

    if (document.getElementById(navId) != null) {

        var tmp = document.getElementById(navId).onclick.toString();

        tmp = tmp.substring(tmp.indexOf(“‘”) + 1, tmp.indexOf(“;”));

        var loadArea = tmp.substring(0, tmp.indexOf(“‘”));

        var roleOrd = (tmp.indexOf(“roleOrd”) == -1) ? -1 : tmp.substring(tmp.indexOf(“roleOrd”), tmp.lastIndexOf(“‘”)).replace(“\\x3d”, “=”);

        crmForm.all.IFRAME_Name.src = (roleOrd == -1) ? GetFrameSrc(loadArea) : GetFrameSrc(loadArea) + “&” + roleOrd;

        //call function onreadystatechange to remove padding and scrollbar

        crmForm.all.IFRAME_Name.attachEvent(‘onreadystatechange’, RemovePadding);

    }

}

function GetFrameSrc(tabSet) {

    if (crmForm.ObjectId != null) {

        var id = crmForm.ObjectId;

        var type = crmForm.ObjectTypeCode;

        var security = crmFormSubmit.crmFormSubmitSecurity.value;

        var path = document.location.pathname.substring(0, document.location.pathname.indexOf(“edit.aspx”)) + “areas.aspx?”;

        return (path + “oId=” + id + “&oType=” + type + “&security=” + security + “&tabSet=” + tabSet);

    }

    else {

        return “about:blank”;

    }

}

//To remove padding

function RemovePadding() {

    if (crmForm.all.IFRAME_Name.readyState == ‘complete’) {

        var IframeObject = crmForm.all.IFRAME_Name.contentWindow.document;

        IframeObject.body.scroll = “no”;

        IframeObject.body.childNodes[0].rows[0].cells[0].style.padding = “0px”;

    }}

Cheer 🙂

2 Comments

Filed under JS Script, MS CRM 4.0

Make left navigation link as default link in a record

I found a question here to set left navigation link as default for ms crm record, while opening ms crm form.

http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/9dd557d3-3828-441b-a6dc-e6c481fdb8c9

We can easily do this through JS, we just need to get ID of particular left navigation item which we can get IE Dev toolbar or Developer Tools

Paste this code on form onload event

var NavItem=document.getElementById(“Paste LeftNavigation item ID”);

if(NavItem!=null)

NavItem.click();

Done !!!

Leave a comment

Filed under JS Script, MS CRM 4.0