Archive
Closing Aspx page on PostBack by suppressing close confirmation
Hi,
Below is the code to close the current .aspx page in the Postback (i.e., On Button click) without “Close” confirmation dialog
// Close the window with no close confirmation
Response.Write(“<script language=’javascript’> { window.open(”, ‘_self’, ”); window.close(); }</script>”);
Hope it helps 🙂
Reading Optionset using CRM 2011 IOrganizationService
Hi,
Below is the code to read “Optionset” using CRM 2011 IOrganizationService.
Below logic reads the Optionset and returns “KeyValue” list (Key = Option Label; Value = Option Value)
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
public List<KeyValuePair<string, int>> GetOptionSet(string entityName, string attributeName, IOrganizationService service)
{
var optionSet = new List<KeyValuePair<string, int>>();
RetrieveAttributeRequest request = new RetrieveAttributeRequest();
request.EntityLogicalName = entityName;
request.MetadataId = Guid.Empty;
request.LogicalName = attributeName;
request.RetrieveAsIfPublished = true;
OrganizationResponse response = service.Execute(request);
if (response != null && response.Results != null)
{
foreach (KeyValuePair param in response.Results)
{
foreach (OptionMetadata option in ((EnumAttributeMetadata)param.Value).OptionSet.Options)
{
string name = option.Label.LocalizedLabels[0].Label.ToString().Trim();
int value = option.Value.Value;
optionSet.Add(new KeyValuePair(name, value));
}
}
}
return optionSet;
}
// Returns option label by value
public string GetOptionLabelByValue(List<KeyValuePair<string, int>> optionSet, int optValue)
{
foreach (KeyValuePair< string, int> optn in optionSet)
{
if (optn.Value == optValue)
{
return optn.Key;
}
}
return string.Empty;
}
// Returns option Value by Label
public int GetOptionValueByLabel(List<KeyValuePair<string, int>> optionSet, string optLabel) { {
foreach (KeyValuePairoptn in optionSet)
{
if (optn.Key) == optLabel)
{
return optn.Value;
}
}
return 0;
}
How Do I call these methods:-
- To read ‘Gender (i.e., gendercode)’ optionset of entity ‘Contact (i.e., contact)’
- Get Optionset dictionary by calling “GetOptionSet()” method
- Call “GetOptionLabelName()” to get Label by Value
- Call “GetOptionValueByLabel()” to get Value by Label
// Get OptionSet First
var optGender = GetOptionSet(“contact”, “gendercode”, orgService);
// Get Option label by value
string optLblGander = GetOptionLabelName(optGender , 1); /* 1 is Value of Male */
// To get Option Value by Label
int optValueGander = GetOptionValueByLabel(optGender , “Male”);
Hope it helps 🙂
New window is opening up on button click in modal dialog
Hi,
In one of my requirement, I am opening an “.aspx” page in modal dialog on CRM ribbon button click.
My .aspx page has a button and when I click on the button , The same page is opening up in another window
Fix :-
- Add “base target=”_self” tag to the .Aspx page’s “head” (Refer below)
<head>
<base target=”_self” />
</head>
Hope it helps 🙂
Stats
- 1,555,883 hits
Tweets
- RT @TaikiYoshidaEN: Awesome to see we have a shiny new public facing website for Power CAT! 😻😻😻 microsoft.github.io/powercat/ #PowerApps #PowerA… 16 hours ago
- RT @ravichada: 🎥 The demo video is ready now. Do check out the Dataverse Security Roles risk assessment tool in action. Leave a comment or… 16 hours ago
- RT @ManuelaPichler_: CoE kit but make it more fluent-y #comingsoon https://t.co/kcSzPqwZhM 16 hours ago
- New Blog Post: C# Basics | Why Interfaces rajeevpentyala.com/2023/01/07/c-b… 2 weeks ago
- New blog post : Dataverse solution import error | Environment variable value cannot be an empty string rajeevpentyala.com/2023/01/05/dat… 3 weeks ago
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- [Code Snippet] Custom Workflow Activity with Input and Output Params
- [Step by Step] Connecting to Azure SQL Server using OLEDB Connection from SSIS
- Power Automate Flows | 'Callback Registration Expander' System Jobs stuck at 'Waiting For Resources'
- [Step by Step] Postman tool with Microsoft Dataverse Web API
- God Mode - Level Up - Dynamics 365 Chrome Extension
- [Step by Step] Dataverse | Plugins | Using Dependent Assemblies
- Auto generate new GUID for ‘uniqueidentifier’ column in SQL Table
- Associate/Disassociate plugin messages in CRM
- Power Apps - 'Environment Variables' and their usage in Canvas Apps