serving the solutions day and night

Pages

Showing posts with label crm javascript. Show all posts
Showing posts with label crm javascript. Show all posts

Wednesday, March 30, 2016

MS Dynamics CRM - Display Unique/Auto Number on the form before save.

My client requirement is display the unique reg number for new contact before the save record.
My Previous blog <a href="http://makdns.blogspot.com/2016/03/ms-dynamics-crm-generate-uniqueauto.html">MS Dynamics CRM - Generate Unique/Auto Number</a> will show the reg number on form after save the new contact. if the user clicks save and close, they can't see the number.

So i come up with the web service concept to generate unique number for new contact and display on the contact screen.
Also i am using SQL Server sys.sequences for generating new number.

Web Service Code

Tuesday, March 29, 2016

MS Dynamics CRM - Login user's security role using javascript

I have one situation, login user has multiple security roles, if the login user has permission for particular role, show some buttons/fields otherwise the hide buttons/fields.

It is not stright forward to find out the security role, So i wrote one javascript to find out the security role.

Here i am checking the user has "Content Manager" security role or not.

var CMRole = CheckUserRole("Content Manager");
if (CMRole) {
    //true to show buttons
} else {
    //false to hide buttons
}


This function will get all the user's security role Id, passing security role id to get the security role name. If it match, it is true otherwise false.
function CheckUserRole(roleName) {
    var currentUserRoles = Xrm.Page.context.getUserRoles();
    for (var i = 0; i < currentUserRoles.length; i++) {
        var userRoleId = currentUserRoles[i];
         var userRoleName = GetRoleName(userRoleId);
         if (userRoleName == roleName) {
            return true;
         }
    }
    return false;
}


This function calling odata web service and get the each security role name.
 function GetRoleName(userRoleId) {
     var selectQuery = "RoleSet?$top=1&$filter=RoleId eq guid'" + userRoleId + "'&$select=Name";
     var odataSelect = GetServerUrl() + selectQuery;
     //alert(odataSelect);
     var roleName = null;
     $.ajax({
         type: "GET",
         async: false,
         contentType: "application/json; charset=utf-8",
         datatype: "json",
         url: odataSelect,
         beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
         success: function (data, textStatus, XmlHttpRequest) {
             var result = data.d;
             if (!!result) {
                 roleName = result.results[0].Name;
             }
         },
         error: function (XmlHttpRequest, textStatus, errorThrown) {
             //alert('OData Select Failed: ' + odataSelect);
         }
     });
     return roleName;
 }

Dynamics CRM - Get selected id from the grid and refresh.

1)Creates a custom button, contains one command (dns.dns_copies.Command.UnCopy)
2)command calling UnCopy javascript (library->$webresource:dns_js/Contact.js) function.
3)command contains 3 parameters
    i)[Crm Parameter]=SelectedControl   (grid name)
   ii)[Crm Parameter]=SelectedControlSelectedItemCount  (number of selected rows)
  iii)[Crm Parameter]=SelectedControlSelectedItemIds (selected entity ids)

Saturday, May 17, 2014

MS Dynamics CRM - Change Grid view background color

My client wants to change the grid view color based on the contact entity address type value is "Ship To". So i added a button in the contact entity "<ribbondiffxml>", but i didn't make it display, you can see there is no command in the "<displayrules>". I added new <customrule> to call the javascript("dns_contact") function ("BackGroundColorGrid") to change the color. Make sure you added jquery in your webresources.

Same way you can change color for the grid.


Friday, September 6, 2013

MS Dynamics CRM 2011 - Display Lists/Views Dynamically

Audit_matchlist.htm - HTML Page Code

This page will build fetchxml, display event list from event entity, matchtype option set, and bind the result in the frame.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
    <meta content="utf-8" http-equiv="encoding"/>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
    <meta http-equiv="CACHE-CONTROL" content="NO-CACHE"/>
    <link href="/WebResources/dns_CSS/audit.css" rel="Stylesheet" />

    <script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
    <script src="/WebResources/dns_JavaScript/Jquery1.4.1.min.js" type="text/javascript" language="javascript"></script>
    <script src="/WebResources/dns_JavaScript/Jason.js" type="text/javascript" language="javascript"></script>
    <script src="/WebResources/dns_JavaScript/advancedfindview.js" type="text/javascript" language="javascript"></script>
    <script src="/WebResources/dns_JavaScript/DataOperations.js" type="text/javascript" language="javascript"></script>
    <script src="/WebResources/dns_JavaScript/audit.js" type="text/javascript" language="javascript"></script>
    <script type="text/javascript">
        var ECMRole = CheckUserRole("ECM");
       
        //alert(window.location.href);

Tuesday, September 3, 2013

MS Dynamics CRM 2011 - Ribbon Drop Down Menu

This blog will guide you, how to create drop down menu from the ribbon. It contains one group or button ('Audit') ,2 drop down menu and their commands/actions.



 1) Create a solution contains Application Ribbons and Site Map.

Monday, August 12, 2013

MS Dynamics CRM - Security Role

I have one situation, login user has multiple security roles, if the login user has permission for particular role, show some buttons/fields otherwise the hide buttons/fields.

It is not stright forward to find out the security role, So i wrote one javascript to find out the security role.

<script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script src="/WebResources/gab_JavaScript/Jquery1.10.2.min.js" type="text/javascript" language="javascript"></script>
<script src="/WebResources/gab_JavaScript/Jason.js" type="text/javascript" language="javascript"></script>

function context() {
    if (typeof GetGlobalContext != "undefined") {
        return GetGlobalContext();
    }
    else {
        if (typeof Xrm != "undefined") {
            return Xrm.Page.context;
        }
    }
}

function GetServerUrl() {
    var Crmurl = window.location;
    var orgName = context().getOrgUniqueName();
    return Crmurl.protocol + "//" + Crmurl.host + "//" + orgName + "/xrmservices/2011/OrganizationData.svc/";
}

Here i am checking the user has "Content Manager" security role or not.

function BookAuditMatch() {
   var ECMRole = CheckUserRole("Book Content Manager");
   if (ECMRole) {
      //Do something
   }
}

This function will get all the user's security role Id, passing security role id to get the security role name. If it match, it is true otherwise false.
function CheckUserRole(roleName) {
    var currentUserRoles = Xrm.Page.context.getUserRoles();
    for (var i = 0; i < currentUserRoles.length; i++) {
        var userRoleId = currentUserRoles[i];
        var userRoleName = GetRoleName(userRoleId);
        if (userRoleName == roleName) {
            return true;
        }
    }
    return false;
}

This function calling odata web service and get the each security role name.
function GetRoleName(userRoleId) {
    var selectQuery = "RoleSet?$top=1&$filter=RoleId eq guid'" + userRoleId + "'&$select=Name";
    var VoterAddress = "";
    var odataSelect = GetServerUrl() + selectQuery;
    //alert(odataSelect);
    var roleName = null;
    $.ajax({
        type: "GET",
        async: false,
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: odataSelect,
        beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
        success: function (data, textStatus, XmlHttpRequest) {
            var result = data.d;
            if (!!result) {
                roleName = result.results[0].Name;
            }
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            //alert('OData Select Failed: ' + odataSelect);
        }
    });
    return roleName;
}

Wednesday, July 31, 2013

Dynamics CRM - Cross-Site Scripting Filter

In CRM, if your customization fetch xml contain extra attribute name which is does not belong in the Saved View, then IE will throw
"Internet Explorer has modified this page to help prevent cross-site scripting. Click here for more information... "



Example
Saved View contains - firstname, lastname
Cusomization fetch XML contain middlename
var fetchBaseXML = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">';
            fetchBaseXML += '    <entity name="contact">';
            fetchBaseXML += '        <attribute name="middlename" />';
            fetchBaseXML += '        <attribute name="lastname" />';
            fetchBaseXML += '        <attribute name="firstname" />';
           
Solution 1
Remove the attribute name from the customization fetch OR Add the attribute name in the Saved View.

Solution 2
Click Tools > Internet options > Security and click the Custom Level... button.
Scroll down the list and click the Disable radio button for the Enable XSS-filter option.
Restart the browser.
Click the Submit button again in the Report Administration screen in Maximo, and the SmartCloud Cost Management reports are now displayed.

Monday, April 22, 2013

CRM Form Customization JavaScript



SAVE and Close Function
Save  -  Xrm.Page.data.entity.save();
Save &  Close  -  Xrm.Page.data.entity.save("saveandclose");
Save &  New  -  Xrm.Page.data.entity.save("saveandnew");
 Close - Xrm.Page.ui.close();

dns_JavaScript/Food.js
Read text box value

Xrm.Page.data.entity.attributes.get("dnsb_foodreason").getValue();
var fName = Xrm.Page.data.entity.attributes.get("fName").getValue();
check value is null or not
if (fName==null) fName = "";

Get html element value
var plFS = document.getElementById("dns_foodstatus");