How to retrieve Attribute Display name from CRM 4.0 Plugin - dynamics-crm

How can I get the Display name of Custom Attribute from CRM Plugin? This code doesn't give me the name. Please let me know. Thank you
DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties["Target"];
String str = (String)entity.Properties["name"];

You'll have to make a call to the MetadataService to get the AttributeMetadata which has a DisplayName property.

Related

Retrieve Plugin not getting triggered

We are on Dynamics CRM 2016 On-Premise. Using a plugin I'm trying to automatically update a field when a user open the CRM Account form, in this example to value "5". Here's my code:
var targetEntity = (Entity)context.OutputParameters["BusinessEntity"];
if (targetEntity == null)
throw new InvalidPluginExecutionException(OperationStatus.Failed, "Target Entity cannot be null");
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);
if (targetEntity.Attributes.Contains("MyField"))
fedTaxId = targetEntity.Attributes["MyField"].ToString();
targetEntity.Attributes.Add("MyField"d, "5");
targetEntity["MyField"] = "5";
service.Update(targetEntity);
I list this in message type 10 (Before Main Operation Outside Transaction).
In Plugin Registration I list this as Post Operation stage and Synchronous.
However when I open the Account form, the page blinks once but the value did not get automatically populated. There is no javascript that would've manipulated this form or value either.
Any suggestion? Thanks.
Two options:
Add a script on the form setting the field value on load. Keep in mind this script should only do its thing if the form type = 2.
(Not recommended) Register a plugin on the synchronous post retrieve message for the entity. Make sure this step sets the field value on the entity object in the OutputParameters collection. Now, keep in mind your form will not be aware of the fact that this field has been modified, so it will not be flagged dirty and it will not automatically be submitted when record changes are being saved. So, in this scenario you would still need to add some JavaScript OR you would need an extra plugin registered on the pre update message of the entity setting the field as desired.

How to get smtp address of current Outlook store

We have user with 3-4 shared email address in Outlook.
I am developing add-in where it will extract the email address of selected store and will get it's contact folder from People.
My problem is I don't know how to get email address of SelectedStore.
Here is my code.
string recipientName = SelectedStore.EmailAddress; // This is what I want to make it work
Outlook.Recipient recip = ns.CreateRecipient(recipientName);
recip.Resolve();
if (recip.Resolved)
{
Outlook.MAPIFolder folderContacts = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderContacts);
}
Any help will be appreciated.
Thank you.
For the mailbox owner, you can either try to read the MAPIFolder.Store property to get to the parent store, then read the PR_MAILBOX_OWNER_ENTRYID property (DASL name "http://schemas.microsoft.com/mapi/proptag/0x661B0102") using Store.PropertyAccessor.GetProperty. You can then use the store owner entry id to call Namespace.GetAddressEntryFromID. Once you have the AddressEntry object, you can use AddressEntry.GetExchangeUser.PrimarySmtpAddress.
Note that PR_MAILBOX_OWNER_ENTRYID property is only available in the online stores. You might want to use Redemption (I am its author) and its RDOExchangeMailboxStore.Owner.SmtpAddress property. RDOExchangeMailboxStore can be retrieved using RDOSession.GetRDOObjectfromOutlookObject(Store) or using RDOSession.GetStoreFromID.
You can also try to retrieve the store entry id and parse it - its format is documented and you can extract the EX type address of the owner. You can then construct the GAL entry id to open the AddressEntry object. From there, you can retrieve the SMTP address.
Just to let you know, I found the solution.
Outlook.MAPIFolder folderContacts = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
should do the trick.

Can't get the language entity with the method _languageRepository.FirstOrDefault(x=>x.Name=langCode)

Please help me solve this issue ,it drivers me mad .Thank you in advance.
Version:3.1.3 Abp ModuelZero MPA
I need to get the language id by language name from Database.
So I inject the Repository as below.
private readonly IRepository<ApplicationLanguage> _languageRepository;
Then I use the below method to get the language entity
var lang = _languageRepository.FirstOrDefault(x=>x.Name==langName);
but the result is null .The parameter is 'zh-TW' and I am sure it exists in database.
The below screenshots for your reference.
var lang = _languageRepository.Where(x=>x.Equals(langName)).FirstOrDefault();
return lang?.Id;
lang?.Id is to handle null.

Is it possible to retrieve schema change information in Dynamics CRM online?

When a custom entity is created, a field is added or changed, someone makes an out-of-box changes to metadata.
How to know who did it and when?
The same for the creation or modification from a UI form. The metadata in CRM doesn't seem to store that information.
I think it is not possible to access information you're asking for. Such a information is not available in the on-premise CRM database and I suppose there is a similar situation with CRM Online
Not exactly what you are looking for. But this will be a good starting point to achieve what you want.
Using RetrieveMetadataChangesRequest, we can get the schema changes like:
Adding a custom entity named sample_SampleEntityForMetadataQuery with
a custom optionset attribute named : sample_ExampleOptionSet
ClientVersionStamp: 296646!10/22/2012 21:42:06
Adding an additional option to the sample_ExampleOptionSet attribute
options
Deleting the sample_SampleEntityForMetadataQuery custom entity
--
Sample code can be found in MSDN/SDK.
protected RetrieveMetadataChangesResponse getMetadataChanges(
EntityQueryExpression entityQueryExpression,
String clientVersionStamp,
DeletedMetadataFilters deletedMetadataFilter)
{
RetrieveMetadataChangesRequest retrieveMetadataChangesRequest = new RetrieveMetadataChangesRequest()
{
Query = entityQueryExpression,
ClientVersionStamp = clientVersionStamp,
DeletedMetadataFilters = deletedMetadataFilter
};
return (RetrieveMetadataChangesResponse)_service.Execute(retrieveMetadataChangesRequest);
}

Get executive workflow name - CRM 4

I have started to write a workflow assembly for CRM 4.0 that should kill any other running workflows with the given name (in my case, all other workflows except him self).
ConditionExpression ce = new ConditionExpression();
ce.AttributeName = "name";
ce.Values = new Object[]{this.WorkflowName}; // Dependency Property
query.EntityName = EntityName.asyncoperation.ToString();
Has anyone an idea, how to get the current workflow name out of the IContextService or something like that?
Best regards
Its a bit of a long way around, but you could use IWorkflowContext.AsyncOperationId to get the ID of the current workflow.
Using that ID you can then query the asyncoperation to get the name of the workflow.

Resources