Custom Validation Package - Order.Tasks.CDFLine

Discussions related to SoftPro Select Server development.

Moderator: Phil Barton

Post Reply
mwalsh
Posts: 10
Joined: Wed Apr 15, 2015 8:49 am

Custom Validation Package - Order.Tasks.CDFLine

Post by mwalsh »

I’m trying to add logic to my server side validation package to prevent users from saving orders where the "Fee:" and "Line:" fields of the "Details" section of the "Requested Tasks" screen are empty for tasks with a description like "Invoice". I have all the logic worked out except what Type of an object is Order.Tasks.CDFLine. The field code browser does show the object reference, but not what type. I was able to determine that the "Fee:" field is a decimal type object, but can't figure out the type of the "Line:" field. I'm not concerned with what the value is, only if it's empty or not empty.

Field Code Browser Reference:
Order.Tasks.CDFLine
Order.Tasks.Fee

Logic:

foreach (var task in tasks)
{
TaskStatusType status = (TaskStatusType)((IOrderItem)task).GetProperty("Status");
string description = (string)((IOrderItem)task).GetProperty("Description");

if (status.ToString() == "Received" && description.ToUpper().Contains("INVOICE"))
{
string cdfline = (string)((IOrderItem)task).GetProperty("CDFLine");//***NEED TO KNOW WHAT TYPE OF OBJECT CDFLINE IS*****
decimal fee = (decimal)((IOrderItem)task).GetProperty("Fee");

if (fee == 0 && cdfline == null)
{
taskNotComplete = taskNotComplete + 1;

}
}
}
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Custom Validation Package - Order.Tasks.CDFLine

Post by BobRichards »

If you don't care what the type is, use a dynamic type - that way you don't have to cast it. Besides, the you cannot perform a compile-time cast since the type returned by Select is only known at runtime. It can come from many different sources.

How about this? (I also used the TaskStatusType enum so you don't have to convert it to a string then test it.)

Code: Select all

foreach (var taskItem in order.Tasks)
{
	IOrderItem task = (IOrderItem)taskItem;
	TaskStatusType status = (TaskStatusType)task.GetProperty("Status");
	string description = (string)task.GetProperty("Description");

	if (status == TaskStatusType.Received && description.ToUpper().Contains("INVOICE"))
	{
		dynamic cdfline = task.GetProperty("CDFLine");
		decimal fee = (decimal)task.GetProperty("Fee");

		if (fee == 0 && cdfline == null)
		{
			taskNotComplete++;
		}
	}
}
Bob Richards, Senior Software Developer, SoftPro
Post Reply