reopen closed or cancel activity with console application - dynamics-crm

I got this error when I try to reopen appointment: "Cannot update Closed or Cancelled Activity"
here is my code:
var connectionString = ConfigurationManager.ConnectionStrings["crmConnection"].ConnectionString;
var conn = CrmConnection.Parse(connectionString);
var service = new OrganizationService(conn);
var stateRequest = new SetStateRequest
{
State = new OptionSetValue(0),
Status = new OptionSetValue(1),
EntityMoniker = entity.ToEntityReference()
};
service.Execute(stateRequest);
I'm getting the entity from RetrieveMultiple(query) where StateCode is "Cancel" or "Complete". I run this code in a Console Application and get that error.
PS:
I wrote my code in the new version but I got this error again:
entity.SetAttributeValue<OptionSetValue>("statecode", 0);
entity.SetAttributeValue<OptionSetValue>("statuscode", 1);
var request = new UpdateRequest { Target = entity };
var response = (UpdateResponse)_organizationService.Execute(request);

Finally, after 8 hours working I got it!. It's so ridiculous but it worths to know. this error raises from another plugin that I had registered before. That plugin was registered on "Update" message when "StateCode" field has changed. I disable that step and my deprecate function has worked!
in exception message, you cannot understand which plugin raise the error.

Please provide the total code. I see here, you statened a new OrganizationService, as you have used one before (for retrieveMultiple).
Maybe using the same service, just fixes your problem :), but with total code we can maybe help more.
In addiont to the deprecated discussion. You use CRM 2015, as it seems to be flagged with it? It is only depricated in D365 as i know (hopefully i am not mistaken here ;) )

Related

Problems with findEntity()

I am having a problem similar to Botframework findEntity() issue.
I have created a node.js botframework app using the azure interface. I am using the azure ide for development (to keep things simple).
The relevant code is:
// Main dialog with LUIS
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
var intents = new builder.IntentDialog({ recognizers: [recognizer] })
/*
.matches('<yourIntent>')... See details at http://docs.botframework.com/builder/node/guides/understanding-natural-language/
*/
.matches('Help',(session, args) => {
var entities = args.entities;
var itype = builder.EntityRecognizer.findEntity(args.entities, 'ItemTypes');
session.send(args.entities[0]["entity"]);
session.send(args.entities[0]["type"]);
session.send('How may I assist you? ' + JSON.stringify(args));
session.send('Value of entity (didnt match) you said: \'%s\'.', itype);
})
the findEntity function returns null in itype (at least that is what I see in the session.send results.
I tried using both args.entities and args.intents.entities, no change.
When I look at the results of the args.entities[0]["entity"] and [type] I do get values. The results of the JSON.stringify are below (also showing it is finding the entity).
How may I assist you?
{"score":0.970185757,"intent":"Help","intents":[{"intent":"Help","score":0.970185757},{"intent":"Joke","score":0.0711096451},{"intent":"Greeting","score":0.0438234434},{"intent":"None","score":0.0408537947},{"intent":"Goodbye","score":0.04074517}],"entities":[{"entity":"stapler","type":"ItemTypes","
I'm assuming there is more but that it was cut off by the chat window.
I'm new to every technology involved and will take any help I can get.

Add a note using the OOB dialog from a webresource

Im working with Microsoft Dynamics CRM. The client is requesting to be able to add notes from a webresources.
I thought that something like this will do the trick:
Xrm.Utility.openEntityForm("annotation", null, parameters);
or even the classic
/main.aspx?etn=annotation&pagetype=entityrecord#
But I receive a "Query Builder Error: The specified record type does not exist in Microsoft Dynamics CRM"
It seems like notes is not something we can open in that way but I cannot found the right way (if even exists!)
Any help?
Maybe this can help someone in the future: This will open a dialog with the Regarding field filled, the textboxs for title and description and the attachments field.
function createNote() {
var EntityID = Xrm.Page.data.entity.getId(); // to get entity id
var ServicerURL = Xrm.Page.context.getClientUrl(); // to get server url
var etc =Xrm.Page.context.getQueryStringParameters().etc; // to get entity type code, make sure not to hard code it, because it could changed in another deployment
var NotesURL = ServicerURL + "/notes/edit.aspx?pId=" + EntityID + "&pType=" + etc;
var features = "copyhistory=no,top=110,left=280,width=600,height=400";
window.open(NotesURL, "", features);
}

Restart AIR MacOS Captive Runtime Bundle Application from code

Could anyone say how to restart it?
I found this sample and try to adapt it for me:
var appLauncher:File;
appLauncher = new File(File.applicationDirectory.nativePath).parent.parent.resolvePath("Contents").resolvePath("MacOS").resolvePath("FlashApp");
var npInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo;
npInfo.executable = appLauncher;
var _args:Vector.<String> = new Vector.<String>;
npInfo.arguments = _args;
var np:NativeProcess = new NativeProcess;
np.start(npInfo);
np.exit();
But I don't understand how it should work.. Now nothing happends when this function called frome one of my classes.
Did you try it with ADL? Or with actually packaged/installed app?
It is related its package structure.
If you try with ADL, it may not work.
Also,
"FlashApp" must be changed to the name of your application,
The last line should be exit(); of your NativeApplication, not np.exit()

Dynamics CRM saving Entity Changes - Getting Errors

I'm really scratching my head with this. I'm trying to use the Dynamics CRM SDK to update an account record. No matter what I try, it's failing. Here goes.
Account sampleAccount = CrmAccount.GetAccountsBySubmissionCode(crmService, "ERZZUP").Single<Account>();
sampleAccount.Name = "AMC Edited";
crmService.Update(sampleAccount);
Gives the error: EntityState must be set to null, Created (for Create message) or Changed (for Update message)
XrmServiceContext ctx = new XrmServiceContext(crmService);
Account sampleAccount = CrmAccount.GetAccountsBySubmissionCode(crmService, "ERZZUP").Single<Account>();
sampleAccount.Name = "AMC Edited";
ctx.UpdateObject(sampleAccount);
ctx.SaveChanges();
Gives the error: The context is not currently tracking the 'account' entity.
XrmServiceContext ctx = new XrmServiceContext(crmService);
Account sampleAccount = CrmAccount.GetAccountsBySubmissionCode(crmService, "ERZZUP").Single<Account>();
sampleAccount.Name = "AMC Edited";
ctx.Attach(sampleAccount);
ctx.UpdateObject(sampleAccount);
ctx.SaveChanges();
Gives the error: The 'account' entity is already attached to a context.
For reference,
1. The Account object is created by the SDK Early Bound Code Generation Tool
2. crmService is the IOrganizationService connection object
3. GetAccounts ... performs a LINQ query and return an IEnumerable
Please help.
Thanks,
Chris.
Refer to http://msdn.microsoft.com/en-us/library/gg695783.aspx, particularly the "Multiple Data Contexts" part. It seems you're using multiple contexts to track the entities. The CrmAccount.GetAccountsBySubmissionCode method just hides this from you.
Make sure within the CrmAccount.GetAccountsBySubmissionCode method to dispose of the context/service before returning the IEnumerable<Account>, or make sure you use the same context/service to Update.

How do you read system jobs in Dynamics CRM?

The CRM SDK says this is possible but the following code fails. Does anyone know why?
var request = new RetrieveMultipleRequest();
var query = new QueryExpression(EntityName.asyncoperation.ToString());
query.ColumnSet = new AllColumns();
request.Query = query;
var response = _connection.Execute(request);
The error is:
<error>\n
<code>0x80040216</code>
<description>An unexpected error occurred.</description>
<type>Platform</type>
</error>
If I change the entity name to account, it works fine.
Found the answer. It appears that it doesn't like the "new AllColumns()" bit. If I specify a column list it works.

Resources