How to get entity values with OData on dynamics crm/365

Try this code below;


function GenerateODataUrl(depth) {

        var url = "";

        if(depth != undefined && depth == true){
             url = window.parent.Xrm.Page.context.getClientUrl() + "/xrmservices/2011/OrganizationData.svc";
        }else{
             url = Xrm.Page.context.getClientUrl() + "/xrmservices/2011/OrganizationData.svc";
        }

	return url;
}

function getAccount(Id) {

	var url = GenerateODataUrl() + "/AccountSet?$filter=AccountId eq guid'" + Id + "'";

	$.ajax({
		type: "GET",
		contentType: "application/json;charset=utf-8",
		datatype: "json",
		url: url,
		async: false,
		cache: false,
		beforeSend: function (XMLHttpRequest) {
			XMLHttpRequest.setRequestHeader("Accept", "application/json");
		},
		success: function (data) {   
			debugger;
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			debugger;
		}
	});
}

#ajax-odata, #dynamics-crm-odata, #javascript-odata-request, #odata

How to call dynamics crm actions on sdk

Try this code below;


OrganizationRequest oRequest = new OrganizationRequest();
oRequest.RequestName = "action_name";
oRequest["Target"] = new EntityReference("entityname", guid);
oRequest["other_input_parameter"] = "test" // like "name" 

OrganizationResponse orr = service.Execute(oRequest);

#action-call-with-sdk, #actions, #dynamics-365, #dynamics-365-action-call, #dynamics-crm

How to get transaction currency info on dynamics crm

Try this code below;


string currencySymbol = "TRY"; // or something else
QueryExpression qe = new QueryExpression();
qe.EntityName = "transactioncurrency";
qe.ColumnSet = new ColumnSet(true);
qe.Criteria.AddCondition(new ConditionExpression("isocurrencycode", ConditionOperator.Equal, currencySymbol ));

Entity currencyEntity = this.OrgService.RetrieveMultiple(qe).Entities.FirstOrDefault().Id;

#dynamics-crm-transaction-currency, #query-expression-transaction-currency, #transaction-currency

Asp.net Mvc maximum request length exceeded error

If you receive this error “Maximum request length exceeded.” greater than 4mb file you want to upload. IIS default max file size 4mb. If you want to upgrade max file upload size, this following code will help you.Add to web.config and try again.

<httpRuntime targetFramework="4.5" maxRequestLength="10485760" />

#asp-net-file-upload, #file-size, #file-upload, #file-upload-error, #max-file-size

How to add lookup filter on custom javascripts

This function bind to form onload “OnLoad”, after calling the “preFilterLookup” function. This method access to form control and add to “addPreSearch” events. In events calling the custom fetchxml functions.

 


function OnLoad() {
preFilterLookup();
}

function preFilterLookup() {
Xrm.Page.getControl("formcontrolelementid").addPreSearch(function () {
addLookupFilter();
});
}

function addLookupFilter() {
fetchXml = "<filter type='and'>"
fetchXml += "<condition attribute='logicalname' operator='eq' value='value' ></condition>";
fetchXml += "</filter>";
Xrm.Page.getControl("formcontrolelementid").addCustomFilter(fetchXml);
}

#custom-js, #lookup, #lookup-filter, #web-resource

How to get global option set values for dynamics crm with c#

This method maybe helping for you


public static List<GlobalOptionSetModel> GetGlobalOptionSetList(string globalOptionSetName, IOrganizationService service)

{

List<GlobalOptionSetModel> result = new List<GlobalOptionSetModel>();

RetrieveOptionSetRequest retrieveOptionSetRequest = new RetrieveOptionSetRequest { Name = globalOptionSetName };

RetrieveOptionSetResponse retrieveOptionSetResponse = (RetrieveOptionSetResponse)service.Execute(retrieveOptionSetRequest);

OptionSetMetadata optionSetMetadata = (OptionSetMetadata)retrieveOptionSetResponse.OptionSetMetadata;

List<OptionMetadata> optionList = optionSetMetadata.Options.ToList();

result = optionList.ConvertAll(z => new GlobalOptionSetModel { Label = z.Label.UserLocalizedLabel.Label, Value = z.Value.ToString(), LanguageCode = z.Label.UserLocalizedLabel.LanguageCode.ToString() });

return result;
}

public class GlobalOptionSetModel
{
public String LanguageCode { get; set; }
public String Value { get; set; }
public String Label { get; set; }
}

 

#csharp-global-option-set, #get-global-option-set-values, #ms-crm-global-option-set-values

How to get picklist option value with localized labels

Sometimes we use in the system can have multiple language options.
In such a situation it may be necessary to show the information in the interface according the to the language options.
Picklist was appropriate in this case we will see how to use multiple languages.

 


//Creating crm service

CrmServiceClient crmSvc = null;
crmSvc = new CrmServiceClient(new System.Net.NetworkCredential("***", "***", "***"), AuthenticationType.AD, "***", "443", "***", useUniqueInstance: false, useSsl: true);

string logicalName = "my_logicalname";
string entityLogicalName = "my_entityname";

//Get metadata for localization

EntityMetadata entityMetadata = crmSvc.GetEntityMetadata(entityLogicalName, EntityFilters.All);
AttributeMetadata attribute = entityMetadata.Attributes.FirstOrDefault(z => z.LogicalName.Equals(logicalName));

if (attribute!= null && attribute.AttributeType == AttributeTypeCode.Picklist)
{
var options = (((Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)(attribute))).OptionSet.Options;
List<PickList> picklist = new List<PickList>();

picklist = options.ToList().ConvertAll(z => new PickList {
Label = z.Label.UserLocalizedLabel.Label,
Value = z.Value.Value.ToString()
});
}

public class PickList
{
public String DefaultValue { get; set; }
public String Value { get; set; }
public String Label { get; set; }
}

Another way

RetrieveEntityRequest rer = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Attributes,
LogicalName ="entitylogicalname"
};

RetrieveEntityResponse reres = (RetrieveEntityResponse)service.Execute(rer);

AttributeMetadata attribute = reres.EntityMetadata.Attributes.FirstOrDefault(z => z.LogicalName.Equals("logicalname"));

if (attribute != null && attribute.AttributeType == AttributeTypeCode.Picklist)
{
 var options = (((Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)(attribute))).OptionSet.Options;
 List<MyClass> picklist = new List<MyClass>();

 picklist = options.ToList().ConvertAll(z => new MyClass
 {
 Text = z.Label.UserLocalizedLabel.Label,
 Value = z.Value.Value.ToString()
 });

}

 

 

#csharp-picklist, #dynamaics-crm-localization, #picklist, #user-localized-label