Page 1 of 1

Server Validation Package - Other Contact "OtherType"

Posted: Thu Aug 27, 2015 2:37 pm
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.";
}

Re: Server Validation Package - Other Contact "OtherType"

Posted: Thu Aug 27, 2015 3:30 pm
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.
	}
}