Tuesday, March 15, 2016

Display View based on Roles in Javascript MSCRM CRM 2011

Hi All,

Display the View based on the role and View

if (document.getElementById('crmGrid') && document.getElementById('crmGrid').GetParameter('viewid')) {
            var currViewId = document.getElementById('crmGrid').GetParameter('viewid');

            if (currViewId) {
                var viewName = getTheViewName(currViewId);

                if (viewName) {
                    if (viewName.toLowerCase() == "Customer Name") {
                        return true;
                    }
Else
{
return false;
}
                }
            }
        }

function getTheViewName()
{
//get the View Name based on Role

}

Bing Map for Account Entity MSCRM

Hi All,

Create a Bing Map based on Latitude and Longitude for MSCRM

var infoboxLayer = new Microsoft.Maps.EntityCollection();
var pinLayer = new Microsoft.Maps.EntityCollection();
function GetMap() {
            var BingMapKey = GetBingMapKey();
            map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {
                credentials:”hdyudyidididididiididdlklklkaksdf”, zoom: 5, center: new Microsoft.Maps.Location(51.5464828, 0.1293497), labelOverlay: Microsoft.Maps.LabelOverlay.hidden
            });
Loopprospect = GetProspectRecords();
Loadmap();
}
Function GetProspectRecords()
{
// Your Account Fetch XML Code Here
}
Function Loadmap(){
//add pushpins
                    pinInfobox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0), { visible: false, offset: new Microsoft.Maps.Point(0, 20) });
                    infoboxLayer.push(pinInfobox);
                    var location = new Microsoft.Maps.Location(Loopprospect[i].attributes.latitude.value, Loopprospect[i].attributes.longitude.value);
                    var pushpinOptions = { icon: serverUrl + '/WebResources/new_RedPushpin' };
                    var pin = new Microsoft.Maps.Pushpin(location, pushpinOptions);
                    pin.Title = Loopprospect[i].attributes.name.value;
                    var getUrlforopenCustomer = serverUrl + "/main.aspx?etc=1&id=" + Loopprospect[i].attributes.accountid.value + "&pagetype=entityrecord";
                    var getSegment = "";
                    var getOpenRevenue = "";
                    if (Loopprospect[i].attributes.new_segment != undefined) {
                        getSegment = Loopprospect[i].attributes.new_segment.formattedValue;
                    }
                    //Check open Revenue
                    if (Loopprospect[i].attributes.openrevenue != undefined) {
                        getOpenRevenue = Loopprospect[i].attributes.openrevenue.value;
                    }
                    pin.Description = "Segment :" + getSegment + "<br/>" + "Open Revenue :" + getOpenRevenue + "<br/>" + "<a target='_blank' href='" + getUrlforopenCustomer + "'>Click to Open Customer</a>";
                    pinLayer.push(pin); //add pushpin to pinLayer
                    Microsoft.Maps.Events.addHandler(pin, 'mouseover', displayInfobox);
                }

                map.entities.push(pinLayer);
                map.entities.push(infoboxLayer);
}
function displayInfobox(e) {
            if (e.targetType == 'pushpin') {
                pinInfobox.setOptions({ title: e.target.Title, description: e.target.Description, visible: true });
                pinInfobox.setLocation(e.target.getLocation());
            }
        }

in the above code am using a Bing map to get Values from Account Entity(Latitude and longitude) and displaying the Value from account Entity.

Get Entity Type code in MSCRM C#

Hi All,

Please find the below script to get Entity Type code in c#

Int getvalue = GetEntityTypeCode(“account”);

private static int GetEntityTypeCode(string EntityName)
{
      RetrieveEntityRequest request = new RetrieveEntityRequest();
      request.LogicalName = EntityName;
      RetrieveEntityResponse response = (RetrieveEntityResponse)crmService.Execute(request);
      int objecttypecode = response.EntityMetadata.ObjectTypeCode.Value;
      return objecttypecode;
}

Get Object Type Code Based on Entity Name in Javascript

Hi All,

Please find the Javascript to get Account Type Code.

function onload() {
    var getAccountCode = getobjecttypecode("account");
    alert(getAccountCode);
}

function getobjecttypecode(entityName) {
    try {
        var lookupService = new RemoteCommand("LookupService", "RetrieveTypeCode");
        lookupService.SetParameter("entityName", entityName);
        var result = lookupService.Execute();

        if (result.Success && typeof result.ReturnValue == "number") {
            return result.ReturnValue;
        }
        else {
            return null;
        }
    }
    catch (ex) {
        throw ex;
    }

}

Debug JS in Browsers

Hi All,

Debug JS Using Browsers

è Open JS Script write debugger in onload Function.
è Publish the JS
è Then open IE and press F12 and refresh the IE.
è Then you can able to see the debugger hit.


(Eg)
function onload() {
debugger;
    // Your code here
}

Monday, March 14, 2016

Retrieve OptionSet Text in CRM 2011 using C# in Plugin

Retrieve Normal(Local) Option Set Text

// Get Normal option set Text
string optionsetText = entity.FormattedValues["new_optionset"];

 or

string optionsetText = entity.GetFormattedAttributeValue("new_optionset"); 

Retrieve Global Option Set Text 

// Retrieves Global Option set Selected Text
        // Parameters: 1. Entity Name   2. Service  3. Global Option Set Name   4. optionset selected value
        public string GetOptionsetText(Entity entity, IOrganizationService service,string  optionsetName,int optionsetValue)
        {
            string optionsetSelectedText = string.Empty;
            try
            {


                RetrieveOptionSetRequest retrieveOptionSetRequest =
                    new RetrieveOptionSetRequest
                    {
                        Name = optionsetName
                    };

                // Execute the request.
                RetrieveOptionSetResponse retrieveOptionSetResponse =
                    (RetrieveOptionSetResponse)service.Execute(retrieveOptionSetRequest);

                // Access the retrieved OptionSetMetadata.
                OptionSetMetadata retrievedOptionSetMetadata = (OptionSetMetadata)retrieveOptionSetResponse.OptionSetMetadata;

                // Get the current options list for the retrieved attribute.
                OptionMetadata[] optionList = retrievedOptionSetMetadata.Options.ToArray();
                foreach (OptionMetadata optionMetadata in optionList)
                {
                    if (optionMetadata.Value == optionsetValue)
                    {
                        optionsetSelectedText = optionMetadata.Label.UserLocalizedLabel.Label.ToString();
                         break;
                    }
                }
            }
            catch (Exception)
            {                throw;
            }
            return optionsetSelectedText;
        }

Friday, March 11, 2016

Unable to load the plugin type MSCRM

Hi All,

I got an Issue while importing a Managed Solution with Plugins, while importing am getting Unable to load the plugin type: Plugin Name

Information:
Already we have Plugin Installed in the Destination Environment, now we are trying to update the Assembly with new steps.

Resolution:
          Create two Solutions
1.    Add Assembly alone without Steps
2.    Add Steps without Assembly

Try importing it with the above steps, You can overcome the above mentioned issues

How to Retrieve Security Role based on Access in Dataverse using FetchXML ?

  Introduction: In tis blog, we will see how to Retrieve Security Role based on Access in Dataverse using FetchXML ? Implementation Steps: N...