views:

29

answers:

1

I've been trying to do this all morning. Anyone have a code snippet (C#) showing how to update an "activity" within CRM via the webservice? I can CreateReadUpdateDelete with entities, but I'm not sure how to do it with Activities.

Can't find anything on google either...

+3  A: 

What are you specifically looking to update? Basically, updating an activity is just like updating any other entity, you just have to use the task entity.

public void CloseTask(CrmService crmsvc, Guid activityid, DateTime start, DateTime end)
{
    ColumnSet cols = new ColumnSet();
    cols.Attributes = new string[] { "activityid", "statecode" };

    task tsk = (task)crmsvc.Retrieve(EntityName.task.ToString(), activityid, cols);
    if(tsk.statecode.Value != TaskState.Open)
         return;

    tsk.actualstart = new CRMDateTime();
    tsk.actualstart.value = start.ToString();
    tsk.actualend =  new CRMDateTime();
    tsk.actualend.value = end.ToString();


    crmsvc.Update(tsk);

    SetStateTaskRequest state = new SetStateTaskRequest();
    state.EntityId = activityid;
    state.TaskState = TaskState.Completed;
    state.TaskStatus = -1; // Let MS CRM decide this property;
    SetStateTaskResponse stateSet = (SetStateTaskResponse)crmsvc.Execute(state);

}

Edit: added some sample code. note, I had to modify what I had to strip some proprietary code, so I don't know if this will actually compile. It's close though.

Moose
Outstanding, exactly what I was looking for, thank you sir.
CraigF
Hmm.. it says that a task with that Guid does not exist. It is an activity.. and I know the guid is there...
CraigF
Here is the actual error message: 0x80040217 task With Id = 84112d9e-db9b-df11-910a-00155d0a3024 Does Not Exist Platform
CraigF
Actually, come to think of it, our activity doesn't even have those taskstates, we have "Pending""Approved""Rejected"...I don't think "task" is going to work here..
CraigF
ack.. sorry.. was just informed, that this is new to um.. a newer version...
CraigF
What version are you using? This should work for 3.0 and 4.0. Is your activity a different, custom entity?
Moose
Custom Activity, sorry, can't say anymore (NDA)
CraigF
That's a good enough answer. Good luck with it, I can't help you there.
Moose