Server Validation Package - Other Contact "OtherType"

Discussions related to SoftPro Select Server development.

Moderator: Phil Barton

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

Server Validation Package - Other Contact "OtherType"

Post by mwalsh »

I’m trying to add logic to my server side validation package to prevent users from saving orders that don’t have a specific Other Contact “OtherType” value of "CLIENT". The below logic works, but for ALL of the Other Contact types not just the ones with a specific OtherType . I can't figure out the correct syntax to either filter the list or loop through the list. Please advise…

IList otherContacts = (IList)iOrder["Others"];

if (otherContacts.Count == 0)
{
e.Cancel = true;
e.Reason = "Validation Error! Order can't be saved without a Contact Type of CLIENT.";
}
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Server Validation Package - Other Contact "OtherType"

Post by BobRichards »

Try this to evaluate each Other contact in the order. By the way, only Other contacts have an "OtherType" property - so it won't work with other contacts.

Code: Select all

# Loop over each Other contact that is present in the order.
IList others = (IList)iOrder["Others"];
foreach (var other in others)
{
	string type = (string)((IOrderItem)other).GetProperty("OtherType");

	if (String.IsNullOrWhiteSpace(type))
	{
		// Error: OtherType is not specified.
	}
	else if (type != "CLIENT")
	{
		// Error: Wrong value for OtherType
	}
	else
	{
		// OtherType value is correct.
	}
}
Bob Richards, Senior Software Developer, SoftPro
Post Reply