Updating a Task

Discussions concerning general integration topics.

Moderator: Phil Barton

Post Reply
josh.nester
Posts: 5
Joined: Thu Oct 04, 2018 5:17 pm

Updating a Task

Post by josh.nester »

HI,

I'm able to retrieve the correct Order and find the desired Task using the SDK/API in a console app like this:

var os = _ss.GetService<IOrderStore>();
var orderinfo = os.Orders.Where(x => x.Number == row.Number).FirstOrDefault();
var order = os.OpenOrder(orderinfo);
var tasks = order.GetProperty("Tasks");
dynamic t = (dynamic)tasks;

Plus a For loop that iterates through "t" to identify the Task to be updated.

What is the best way to then make the update to the Task and save it back to the db through the SDK?

In the SDK documentation that refers to creating a new Note, the ApplyChanges method on the Order object is used to add a new Note. Would updating a Note (or Task in this case) be handled in a similar way?

Alternatively, the ITaskManager has an ApplyChanges method as well. Would it be a better approach to find the Task like i mentioned above and use the ApplyChanges method on ITaskManager instead to update the Task? If so, would I need to "unbox" the Task object I find on the Order and "rebox" it into a more appropriate Task related object type. The Task that is exposed by the Order object is some variation of a .Snapshot<Task> object, and I've tried updating that and using the ApplyChanges on Order but was unsuccessful.

Just throwing my observations out there in hope of some helpful feedback, any other input related to updating Tasks via the SDK/API using a console app would be appreciated.

Thanks.
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: Updating a Task

Post by John Morris »

The order task is not the same thing as the ITaskManager area. Although they share a common term (task) they refer to very different concepts.

In order to save your order tasks, simply save the order using the IOrderStore::ApplyChanges method. Most order data is saved this way.

The ITaskManager area is used for storing generic key/value pair data when performing more low level operations. It is mostly to be used by infrastructure code.

Hope that helps!
John Morris
Sr. Software Architect
SoftPro
josh.nester
Posts: 5
Joined: Thu Oct 04, 2018 5:17 pm

Re: Updating a Task

Post by josh.nester »

That's helpful thanks. I'm now trying to save the Order as you mentioned, but its throwing this error.

{"The order has unresolved errors. Any outstanding errors must be resolved before the order can be saved."}

Where would i find more details on errors associated with the Order that would prevent updating? I dont see any helpful info in the places obvious to me (Inner Exception, Errors property on object, Order errors indicators in UI). Some of the text in the UI for the Order Im trying to update is red, but my understanding is that that color is just indicating more significant fields in this case. Any thoughts? Thanks again. -Josh
josh.nester
Posts: 5
Joined: Thu Oct 04, 2018 5:17 pm

Re: Updating a Task

Post by josh.nester »

Regarding my post above. Would a Status of Cancelled on an Order have any impact on the Orders ability to be saved?
josh.nester
Posts: 5
Joined: Thu Oct 04, 2018 5:17 pm

Re: Updating a Task

Post by josh.nester »

Just ran some code based off this post:
viewtopic.php?f=6&t=568&p=2400&hilit=Th ... rors#p2400

No messages are being returned, so looks like no errors. But the same exception is still being thrown.
josh.nester
Posts: 5
Joined: Thu Oct 04, 2018 5:17 pm

Re: Updating a Task

Post by josh.nester »

I've tried a few more things.

If I dont update anything on the Task object before I try to ApplyChanges through the Order object, I get a "Failed to add item" message in the resulting Exception.

If I update the CompletedDate field, i get the first exception I mentioned in this thread.

It seems like maybe other fields need to be updated as well when updating the CompletedDate field...could that be causing the error I'm getting? Is there a list of fields that need to be updated when updating a Task's CompletedDate field?
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: Updating a Task

Post by John Morris »

Try these same steps in the GUI. That is the easiest way to find out the required fields.
John Morris
Sr. Software Architect
SoftPro
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Updating a Task

Post by BobRichards »

Let's start over. Try to replicate this setup and make sure there are no errors then we'll work out from there. In this example, I have manually created an order, added a single Checklist Task and set the name. Below, I open the order, verify the name is read correctly (in the debugger Locals window) then set the Description to the current time.

Code: Select all

IOrderStore os = ...
IOrderInfo oi = os.Orders.Where(t => t.Number == "2018100004").FirstOrDefault();
using (IOrder order = os.OpenOrder(oi, OrderEditMode.ReadWrite))
{
    IList tasks = (IList)order.GetProperty("Tasks");
    IOrderItem firstTask = (IOrderItem)tasks[0];
    string description = (string)firstTask.GetProperty("Description");

    firstTask.SetProperty("Description", DateTime.Now.ToShortTimeString());

    os.ApplyChanges(order);    // Save the order contents (will update necessary SQL tables)
    os.CloseOrder(order);
}
Open the order and look at the task. Did the Description field update? Now start adding changes and let me know when you hit a problem.

Observations:
  • When you are looking at the Tasks collection, you are getting both Checklist AND Requested Tasks. I assume you are only making changes appropriate to the task type you have from your search.
  • You mentioned "update to the Task and save it back to the db". If you are viewing the pfm.Task table, you will see the change in Description value each time the order is saved. The pfm tables are provided for searching and reports. Do not alter them since table changes will NEVER flow back into the order.
Bob Richards, Senior Software Developer, SoftPro
Post Reply