Tuesday, March 15, 2016

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

Wednesday, March 9, 2016

Form Types in MSCRM

Hi,

Get Form Type in MSCRM
Javascript to Get Form Type

Xrm.Page.ui.getFormType()

Below is the Form Types in MSCRM
Form Type
Value
Undefined
0
Create
1
Update
2
Read Only
3
Disabled
4
Quick Create (Deprecated)
5
Bulk Edit
6
Read Optimized (Deprecated)
11



Set Focus in MSCRM for a New Field.

Hi,

In CRM there is a new feature to set Focus to Particular Field. Use the below Javascript to achive the same.


Xrm.Page.ui.controls.get("AttributeName").setFocus();

Regards,
Ram


Day 11 - Customizing Option Sets Dropdown Fields with JavaScript

  In this Blog, we will see how to Customizing Option Sets Dropdown Fields with JavaScript label1 = formContext.getAttribute( "bosch_op...