Wednesday, August 29, 2012

Crm 2011-Disbling Ribbon button based on Form field value

1.Create a new button using visual ribbon editor 
2.Open Enable rules tab ,click add button and choose ValueRule as follows

 

3.Enter the field name and value as follows

Note: For OptionSet fields,value is the OptionValue ,not the option Label 

For more details

http://howto-mscrm.blogspot.in/2011/04/how-to-series-5-how-to-use-valuerule.html

CRM 2011 - Disabling all Fields on a Form to make read only form //based on two option field by javascipt

function doesControlHaveAttribute(control) {
    var controlType = control.getControlType();
    return controlType != "iframe" && controlType != "webresource" && controlType != "subgrid";
}

function disableFormFields(onOff) {
    Xrm.Page.ui.controls.forEach(function (control, index) {
        if (doesControlHaveAttribute(control)) {
            control.setDisabled(onOff);
        }
    });
}

function setupFormVisiblity()
{
    var dependantControl = Xrm.Page.ui.controls.get("jmh_isrmsstockitem");
        if ((dependantControl != "undefined") && (dependantControl != null)) 
{
            var attribute = dependantControl.getAttribute();
            var depandantFieldValue = attribute.getValue();
            //set visible based on depandant fields value
            if (depandantFieldValue == true) //based on two option field
 {
          disableFormFields(true);
   }
}
}

Note: call  setupFormVisiblity  javascipt method OnLoad Event of Form only..

MS Crm 2011-Launching a Dialog process when clicking ribbon button


   1.  Create a new  web resource (javascipt) with following code

  function CallDialog(dialogId,typeName,recordId) {
    var url = Xrm.Page.context.getServerUrl();
    recordId=recordId.replace("{", "");

    recordId=recordId.replace("}", "");
 
    dialogId=dialogId.replace("{", "");

    dialogId=dialogId.replace("}", "");

    url += "/cs/dialog/rundialog.aspx?DialogId=%7b"+dialogId.toUpperCase()+"%7d&EntityName="+typeName+"&ObjectId=%7b"+recordId+'%7d';
  
    window.showModalDialog(url);
}

2. Create a new dialog process

3.Create a new button using visual ribbon editor and pass parameter  as follows


Function Name:CallDialog
Library: $webresource:<created web resource name>
1. String parameter Value: < Id of dialog process to be launched>
2.String parameter Value: <Entity  name From where dialog will be launched>
3.Crm parameter: FirstPrimaryItemId //to pass record id

Monday, August 27, 2012

Opening URL Addressable Forms to Create new Related Records

refer these url..

http://blogs.msdn.com/b/dmcdonald/archive/2012/05/16/opening-url-addressable-forms-to-create-new-related-records.aspx

http://gtcrm.wordpress.com/tag/ribbon/

http://msdn.microsoft.com/en-us/library/cc150850.aspx

Thursday, August 23, 2012

Crm 2011 JavaScript to set visiblity based on option set value

function SetVisiblity()
{
var option=Xrm.Page.getAttribute("customertypecode").getSelectedOption();
if(option!=null)
{
var x=option.text;
if(x=="Supplier")
{
Xrm.Page.getControl("jmh_supplierstatus").setVisible(true);

Xrm.Page.getControl("jmh_sendpoviaemail").setVisible(true);
Xrm.Page.ui.navigation.items.get("nav_jmh_account_jmh_requisition_Supplier").setVisible(true);
Xrm.Page.ui.navigation.items.get("nav_jmh_account_jmh_purchaseorder_Supplier").setVisible(true);
Xrm.Page.ui.navigation.items.get("nav_jmh_account_jmh_purchaseinvoice_Supplier").setVisible(true);

 Xrm.Page.ui.tabs.get("details").setVisible(false);
 Xrm.Page.ui.tabs.get("administration").setVisible(false);
}
else
{
Xrm.Page.getControl("jmh_supplierstatus").setVisible(false);

Xrm.Page.getControl("jmh_sendpoviaemail").setVisible(false);
Xrm.Page.ui.navigation.items.get("nav_jmh_account_jmh_requisition_Supplier").setVisible(false);
Xrm.Page.ui.navigation.items.get("nav_jmh_account_jmh_purchaseorder_Supplier").setVisible(false);
Xrm.Page.ui.navigation.items.get("nav_jmh_account_jmh_purchaseinvoice_Supplier").setVisible(false);
 Xrm.Page.ui.tabs.get("details").setVisible(true);
 Xrm.Page.ui.tabs.get("administration").setVisible(true);
}
}
else
{
Xrm.Page.getControl("jmh_supplierstatus").setVisible(false);

Xrm.Page.getControl("jmh_sendpoviaemail").setVisible(false);
Xrm.Page.ui.navigation.items.get("nav_jmh_account_jmh_requisition_Supplier").setVisible(false);
Xrm.Page.ui.navigation.items.get("nav_jmh_account_jmh_purchaseorder_Supplier").setVisible(false);
Xrm.Page.ui.navigation.items.get("nav_jmh_account_jmh_purchaseinvoice_Supplier").setVisible(false);

 Xrm.Page.ui.tabs.get("administration").setVisible(true);
 Xrm.Page.ui.tabs.get("details").setVisible(true);
}
}

Wednesday, August 22, 2012

Javascript To restrict "to" party list only with users and should not include contacts, accounts and leads

function RestrictUser()
{
document.getElementById("to").setAttribute("lookuptypes", "8");
document.getElementById("to").setAttribute("defaulttype", "8");
document.getElementById("to").setAttribute("lookuptypeIcons", "/_imgs/ico_16_8.gif");
}

Wednesday, August 15, 2012

Linkedin Java script API - Company search and People search Sample code

  function CompanySearch(CompanyName) {
       
            if (IN.User.isAuthorized()) {
                var keywords = CompanyName.toString();
                IN.API.Raw("/company-search:(facets,companies:(id,name,universal-name,website-url,logo-url,description))")
              .params({ "keywords": keywords })

              .result(function (result) { /* handle result */
                  var Companies = result;
                  slCtl.Content.companySearch.ShowCompanyProfile(JSON.stringify(Companies));
              })

              .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); });
            }
            else {
                IN.User.authorize(function () {
                    var keywords = CompanyName.toString();
                    IN.API.Raw("/company-search:(facets,companies:(id,name,universal-name,website-url,logo-url,description))")
              .params({ "keywords": keywords })
              .result(function (result) { /* handle result */
                  var Companies = result;
                  slCtl.Content.companySearch.ShowCompanyProfile(JSON.stringify(Companies));
              })
              .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); });


                });
            }

        }




        function PeopleSearchval(param1, firstname, lastname, company) {
         
            if (IN.User.isAuthorized()) {
                var keywords = param1.toString();
                var fname = firstname.toString();
                var lname = lastname.toString();
                var companyname = company.toString();

                IN.API.PeopleSearch()
         .fields("id", "firstName", "lastName", "distance", "siteStandardProfileRequest", "picture-url", "positions:(company:(name),title)")
                 .params({ "keywords": keywords, "count": 25, "sort": "relevance", "first-name": fname, "last-name": lname, "company-name": company })
         .result(displayPeopleSearches)

         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
             );
//                      var listCount = 20;
//                    url = "/people-search:(people:(id,first-name,last-name,picture-url,distance,siteStandardProfileRequest),num-results)?facets=network&facet=network,F,S,A,O"
//                    url += '&count=25' + listCount;
////                    url += '&keywords=' + keywords;
//                    url += '&first-name=' + "";
//                    url += '&last-name=' + "";
//                    url += '&company-name=' + companyname;

//                    //        url += "&facet=location," + theLocation;

//                    IN.API.Raw(url)
//                .result(displayPeopleSearches)
//         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
//             );
            }
            else {
                //            if (IN.User.authorize()) {
                IN.User.authorize(function () {
                    var keywords = param1.toString();
                    var fname = firstname.toString();
                    var lname = lastname.toString();
                    var companyname = company.toString();

                    IN.API.PeopleSearch()
         .fields("id", "firstName", "lastName", "distance", "siteStandardProfileRequest", "picture-url", "positions:(company:(name),title)")
                 .params({ "keywords": keywords, "count": 20, "sort": "distance", "facet": "network", "first-name": fname, "last-name": lname, "company-name": company })
         .result(displayPeopleSearches)
         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
             );

                    //            }
                });

            }

            //        var listCount = 20;
            //        url = "/people-search:(people:(id,first-name,last-name,picture-url,distance,siteStandardProfileRequest),num-results)?facets=network&facet=network,F,S,A,O"
            //        url += '&count=25' + listCount;
            //        url += '&keywords=' + keywords;
            //        url += '&first-name=' + fname;
            //        url += '&last-name=' + lname;

            //        //        url += "&facet=location," + theLocation;

            //        IN.API.Raw(url)
            //    .result(displayPeopleSearches);
        }
//        var relations = new Array();

//        var membervalues = null;
//        var members = null;
//        var relval = null;
        function displayPeopleSearches(peopleSearchValues) {
//            membervalues = peopleSearchValues;

            slCtl.Content.contactSearch.ShowPeoples(JSON.stringify(peopleSearchValues));
          }
        function getrelations(idvalue) {
        
            IN.API.Raw('/people/id=' + idvalue + ':(id,distance,relation-to-viewer:(distance,related-connections:(id,distance,first-name,last-name,picture-url)))').result(display);


        }
        function display(searchresults) {
          
//            var relatioships = JSON.stringify(searchresults);
            slCtl.Content.contactSearch.ShowRelations(JSON.stringify(searchresults));
        }
  function CompanySearch(CompanyName) {
       
            if (IN.User.isAuthorized()) {
                var keywords = CompanyName.toString();
                IN.API.Raw("/company-search:(facets,companies:(id,name,universal-name,website-url,logo-url,description))")
              .params({ "keywords": keywords })
              .result(function (result) { /* handle result */
                  var Companies = result;
                  slCtl.Content.companySearch.ShowCompanyProfile(JSON.stringify(Companies));
              })
              .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); });
            }
            else {
                IN.User.authorize(function () {
                    var keywords = CompanyName.toString();
                    IN.API.Raw("/company-search:(facets,companies:(id,name,universal-name,website-url,logo-url,description))")
              .params({ "keywords": keywords })
              .result(function (result) { /* handle result */
                  var Companies = result;
                  slCtl.Content.companySearch.ShowCompanyProfile(JSON.stringify(Companies));
              })
              .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); });


                });
            }

        }




        function PeopleSearchval(param1, firstname, lastname, company) {
            // Call the PeopleSearch API with the viewer's keywords
            // Ask for 4 fields to be returned: first name, last name, distance, and Profile URL
            // Limit results to 10 and sort by distance
            // On success, call displayPeopleSearch(); On failure, do nothing.


            //        IN.User.authorize(function () {//            IN.API.Profile("me")
            //            //    .result(function (result) {
            //            //        alert(JSON.stringify(result));
            //            //    });

            //        });
            //               IN.Event.on(IN, "auth", onLinkedInAuth);
            if (IN.User.isAuthorized()) {
                var keywords = param1.toString();
                var fname = firstname.toString();
                var lname = lastname.toString();
                var companyname = company.toString();

                IN.API.PeopleSearch()
         .fields("id", "firstName", "lastName", "distance", "siteStandardProfileRequest", "picture-url", "positions:(company:(name),title)")
                 .params({ "keywords": keywords, "count": 25, "sort": "relevance", "first-name": fname, "last-name": lname, "company-name": company })
         .result(displayPeopleSearches)
         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
             );
//                      var listCount = 20;
//                    url = "/people-search:(people:(id,first-name,last-name,picture-url,distance,siteStandardProfileRequest),num-results)?facets=network&facet=network,F,S,A,O"
//                    url += '&count=25' + listCount;
////                    url += '&keywords=' + keywords;
//                    url += '&first-name=' + "";
//                    url += '&last-name=' + "";
//                    url += '&company-name=' + companyname;

//                    //        url += "&facet=location," + theLocation;

//                    IN.API.Raw(url)
//                .result(displayPeopleSearches)
//         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
//             );
            }
            else {
                //            if (IN.User.authorize()) {
                IN.User.authorize(function () {
                    var keywords = param1.toString();
                    var fname = firstname.toString();
                    var lname = lastname.toString();
                    var companyname = company.toString();

                    IN.API.PeopleSearch()
         .fields("id", "firstName", "lastName", "distance", "siteStandardProfileRequest", "picture-url", "positions:(company:(name),title)")
                 .params({ "keywords": keywords, "count": 20, "sort": "distance", "facet": "network", "first-name": fname, "last-name": lname, "company-name": company })
         .result(displayPeopleSearches)
         .error(function error(e) { /* do nothing */alert(JSON.stringify(e)); }
             );

                    //            }
                });

            }

            //        var listCount = 20;
            //        url = "/people-search:(people:(id,first-name,last-name,picture-url,distance,siteStandardProfileRequest),num-results)?facets=network&facet=network,F,S,A,O"
            //        url += '&count=25' + listCount;
            //        url += '&keywords=' + keywords;
            //        url += '&first-name=' + fname;
            //        url += '&last-name=' + lname;

            //        //        url += "&facet=location," + theLocation;

            //        IN.API.Raw(url)
            //    .result(displayPeopleSearches);
        }
//        var relations = new Array();

//        var membervalues = null;
//        var members = null;
//        var relval = null;
        function displayPeopleSearches(peopleSearchValues) {
//            membervalues = peopleSearchValues;

            slCtl.Content.contactSearch.ShowPeoples(JSON.stringify(peopleSearchValues));
          }
        function getrelations(idvalue) {
        
            IN.API.Raw('/people/id=' + idvalue + ':(id,distance,relation-to-viewer:(distance,related-connections:(id,distance,first-name,last-name,picture-url)))').result(display);


        }
        function display(searchresults) {
          
//            var relatioships = JSON.stringify(searchresults);
            slCtl.Content.contactSearch.ShowRelations(JSON.stringify(searchresults));
        }