Trying to change owner of account on CRM 4.0 using a plugin - plugins

I am creating a plugin for Microsoft Dynamics CRM 4 that will change the owner of the account entity according to the value of another lookup field. Now I have managed to get the GUID of the user that will be acting as the 'Owner' of the account. So far so good.
The problem arises when I try to change the owner. I am trying to use AssignRequest but it is not working. When I try to execute the request I get a SoapException on the C# Debugger, and the webservice outputs a dialog stating:
"The requested record was not found or you do not have sufficient permissions to view it"
Below is the code I am using:
TargetOwnedAccount target = new TargetOwnedAccount();
SecurityPrincipal assignee = new SecurityPrincipal();
assignee.Type = SecurityPrincipalType.User;
assignee.PrincipalId = context.InitiatingUserId;
target.EntityId = ownerGuid; //this is the GUID I am retrieving from the other lookup field
AssignRequest assign = new AssignRequest();
assign.Assignee = assignee;
assign.Target = target;
AssignResponse res = (AssignResponse)crmService.Execute(assign); //this is where i get the exception
I hope I haven't missed anything.
Any help would be much appreciated :)
Thanks

Ok i managed to solve this finally. It had been staring directly at my face :P
I was entering the wrong ID's at the wrong place. I needed to set the 'assignee.PrincipalId' to the 'ownerGuid' and then set the 'target.EntityId' to the current account id. The new code is as follows:
TargetOwnedAccount target = new TargetOwnedAccount();
SecurityPrincipal assignee = new SecurityPrincipal();
assignee.Type = SecurityPrincipalType.User;
assignee.PrincipalId = ownerGuid; //this is the GUID I am retrieving from the other lookup field
target.EntityId = ((Key)entity.Properties["accountid"]).Value;
AssignRequest assign = new AssignRequest();
assign.Assignee = assignee;
assign.Target = target;
AssignResponse res = (AssignResponse)crmService.Execute(assign);
Cant believe i spent 8 hours yesterday looking at it and then today I realised immediately :P

Related

Moodle - update_moduleinfo - invalid course module id

I'm currently building a new moodle plugin. I'm using add_moduleinfo and update_moduleinfo. To add a new attandance atictivity in a course and update it later on.
Sadly I'm facing the issue that update_moduleinfo always throws an "invalid course module id" error. I already checked the cm entry in my database to ensure im using the right module instance.
I dont really know what to do.
$cm = get_coursemodule_from_instance($moduleName, $activityID, $course->id);
$moduleinfo = update_moduleinfo($cm, $moduleinfo, $course); <-- Error
Thats how I try to update the entry.
I also found that post. Didn't help anything.
Moodle - Invalid course module ID
I found the issue myself:
$moduleinfo->introeditor['format'] = FORMAT_HTML;
$moduleinfo->introeditor['text'] = "INTRO TEXT";
$moduleinfo->coursemodule = $cm->id;
list($cm, $moduleinfo) = update_moduleinfo($cm, $moduleinfo, $course, null);
In order to use this function the above mentioned properties need to exist in order to perform a update.

Export Standard/Extended User Greetings (Exchange 2016) - For Use In XMedius AVST

In an earlier post on June 18, 2018 (my birthday BTW), a user asked "Hopefully a simple question - at one time I know when user's recorded their personal greetings for UM voicemail in o365 (regular greeting and/or extended absence greeting) these were stored in their Exchange inbox using a special item type (i.e. "IPM.Configuration.Um.CustomGreetings.External"). However setting up my test o365 setup, getting UM configured and all that, after recording my personal greeting and going through each item starting from the root of my inbox, (some 900+ items - lots of odd stuff in there) - I don't see anything like this any more. Lots of log, activity items, some messages but nothing about greetings. Extracting everything that could cast to an email type to a folder I went through each one - nothing promising. anyone have any clues where the custom greetings for users UM (not auto attendant recordings - that's a different beast) has gone off to and how to get to it?" After reading through the answers as well as the code that was provided by Jeff Lindborg, I thought that I was getting somewhere. With a lot of trial and error, I was finally able to get the EWS-FAI module installed as well as the Exchange Web Services API. Unfortunately, when it came to running the provided code, this is where I am stumped. I'm not a developer or 'coder' in any form, but I'm always looking for effective and efficient methods to do my work. With that said, I'm trying to run this on a Win10 workstation, but can't seem to figure out which program this needs to run within. I've tried Powershell, but that doesn't work. I have access to the necessary accounts for mailbox impersonation as well as any other permissions needed. I've provided the code that was originally supplied for review. Any additional help would be greatly appreciated.
Code
ExchangeService _service;
_service = new ExchangeService(ExchangeVersion.Exchange2016); // Exchange2013_SP1);
_service.Credentials = new WebCredentials("user#domain", "myPw");
_service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
//select the user you're fetching greetings for
_service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "user#domain");
//get the root folder for the current account
var oParamList = new List<FolderId> {WellKnownFolderName.Root};
var oTemp = _service.BindToFolders(oParamList, PropertySet.FirstClassProperties);
var oRoot = oTemp.First().Folder;
var oView = new ItemView(50)
{
PropertySet = new PropertySet(BasePropertySet.FirstClassProperties),
Traversal = ItemTraversal.Associated
};
SearchFilter oGreetingFilter = new SearchFilter.ContainsSubstring(ItemSchema.ItemClass,
"IPM.Configuration.Um.CustomGreetings", ContainmentMode.Substring, ComparisonMode.IgnoreCase);
var oResults = _service.FindItems(oRoot.Id, oGreetingFilter, oView);
//fetch the binary for the greetings as values
var oPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
var oRoamingBinary = new ExtendedPropertyDefinition(31753, MapiPropertyType.Binary);
oPropSet.Add(oRoamingBinary);
_service.LoadPropertiesForItems(oResults, oPropSet);
var strFileName = "";
foreach (var oItem in oResults.Items)
{
if (oItem.ItemClass.Equals("IPM.Configuration.Um.CustomGreetings.External",
StringComparison.InvariantCultureIgnoreCase))
strFileName = "jlindborg_Standard.wav";
if (oItem.ItemClass.Equals("IPM.Configuration.Um.CustomGreetings.Oof",
StringComparison.InvariantCultureIgnoreCase))
strFileName = "jlindborg_Extended.wav";
File.WriteAllBytes("d:\\" + strFileName, (byte[]) oItem.ExtendedProperties.First().Value);
}
}
The code you posted is c# so you would need to use Visual Studio to create a C# application add a reference to the EWS Managed API and compile that for it to work (you'll need to engage a developer or learn some basic coding).
EWS-FAI is a powershell module it should be able to return that item and you should be able to write that to a file eg something like
$MailboxName = "mailbox#domain.com"
$Item = Get-FAIItem -MailboxName $MailboxName -ConfigItemName Um.CustomGreetings.External -Folder Inbox -ReturnConfigObject
[System.IO.File]::WriteAllBytes(("C:\temp\" + $MailboxName + ".wav"),$Item.BinaryData)

Azure AD Graph API ApproleAssignment does not allow zero GUID

I am getting an error when trying to add AppRoleAssignment for a user:
{"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"One or more properties are invalid."},"date":"2017-10-21T14:49:42","requestId":"3aacf13e-5620-40da-8fd0-fb2d4130f171","values":null}}
When i use an actual ApproleId, everything works fine. However, when i set
AppRoleAssignment.Id = new Guid(); i get the above error;
This does not make sense, because the documentation says that this is allowed
by setting zero GUID and the same has been stressed in other posts on SO.
What am i missing here?
Full code:
AppRoleAssignment appRoleAssignment = new AppRoleAssignment()
{
Id = new Guid(),
ResourceId = Guid.Parse(servicePrincipal.ObjectId),
PrincipalId = Guid.Parse(user.ObjectId),
PrincipalType = "User"
};
user.AppRoleAssignments.Add(appRoleAssignment);
await user.UpdateAsync();
Based on my experience, there are two scenarios we may get this issue.
First, if there is customize roles in the service principal you want to assign the default role.
Second, if we have already assigned the default role to that person before.
Please check whether you are in one of these two scenarios and let me know if you still have the problem about this issue.

Alfresco - Using email notification template not working properly

I'm using out-of-the-box Alfresco 4.2.f, without customizations, and i'm trying to set the email notification whether a new document in added in a certain folder.
So i've added a rule to the folder and i've set as Perform Action "Send email" using as template "notify_user_email_it.html.ftl".
If i insert a document, i don't receive the email and here is the error in the log:
Expression person is undefined on line 38, column 57 in workspace://SpacesStore/55088e2c-05ac-4264-8396-ee6f3c7021ad.
The problematic instruction:
----------
==> ${person.properties.firstName} [on line 38, column 55 in workspace://SpacesStore/55088e2c-05ac-4264-8396-ee6f3c7021ad]
----------
If i remove from the template the string ${person.properties.firstName} then the rule works properly but the mail i receive is not as expected, all the interesting informations are shown as in the original FTL. Attached the email received to understand better.
Really strange since i've not customized anything, maybe this is a BUG but i didn't find anything on JIRA...
Someone has the same behaviour? Possible work-arounds?
Thanks in advance!
According to this JIRA, it's not really a bug it just doesn't work for the admin user.
Have you tried it with a normal user?
--- Update ---
Maybe cause it's bug or an unimplemented feature something like the following to fix it in the template:
<#if person??>
.... set your person properties first & lastname
<#else>
.... is sure to be admin, so set the admin
</#if>
You have to pass the parameters to emails templates
you may try with this example
var template = "Data Dictionary/Email Templates/Workflow Notification/<<Your File>>.html.ftl";
var mail = actions.create("mail");
mail.parameters.to = "xyx#gmail.com";
mail.parameters.subject="Hello";
mail.parameters.text="blablabla";
mail.parameters.template = companyhome.childByNamePath(template);
var templateArgs = new Array();
templateArgs['workflowTitle'] = "789789";
templateArgs['workflowDescription'] = "879789";
templateArgs['workflowId'] = "879789";
var templateModel = new Array();
templateModel['args'] = templateArgs;
mail.parameters.template_model = templateModel;
mail.execute(bpm_package);
then you can get parameters using ${args.workflowTitle} in your Email template ftl file

CRM 2011 - CloseIncidentRequest - Throws Exception when registered on Create Case Post Event

I am trying to get a plugin registered on the case ("incident") create post synchronous event to successfully call the CloseIncidentRequest. I have the CloseIncidentRequest working successfully on the case update post event but on the create I keep getting the "Need to start a transaction before commit" exception.
Does anyone know if this is a known issue, or has anyone got this running on the case create post event? I have seen posts around changing from synchronous to asynch - and if I change the plugin to run asynch, that does work - but ideally I want this to run this synchronously, so that the user can see that the case has been resolved when pressing save.
private const int IncidentResolutionStatus_Closed = 2;
private const int IncidentStatusCode_ProblemSolved = 5;
Entity resolution = new Entity("incidentresolution");
resolution["subject"] = "Case Resolved";
resolution["incidentid"] = new EntityReference("incident", IncidentId);
resolution["timespent"] = timespent;
resolution["statuscode"] = new OptionSetValue(IncidentResolutionStatus_Closed);
CloseIncidentRequest closeincidentRequest = new CloseIncidentRequest()
{
IncidentResolution = resolution,
Status = new OptionSetValue((int)IncidentStatusCode_ProblemSolved)
};
service.Execute(closeincidentRequest);
Try resolving the case manually (through the CRM interface) and you probably will get the same error (like me).
If so it's not related to your plugin code (or SDK), but on some missing information when you created the case.
Check if on the case you are trying to resolve there is no missing required field. In my case the error was that the Client name was null (there was a client record but its name was null) and it was causing the error.