C# (Nothing) String Reference

Questions about and code samples for custom order rules and validation within Select.
Post Reply
johnpbzdon
Posts: 11
Joined: Mon May 09, 2016 10:07 am

C# (Nothing) String Reference

Post by johnpbzdon »

Hello,
We are trying to create a Custom Validation based on no Title Company selected in SoftPro Select. In C# we were able to reference (Nothing) selected for Order Type based on the logic below.
var orderType = enums.GetEnum<IOrderType>();
var ot_blank = orderType.Values.FirstOrDefault(i => String.IsNullOrEmpty(i.Name));
We were able to use the variable we created “ot_blank” to create rules based on nothing selected in the Order Type field.
We are aware that for date fields you can simply reference NULL in C# and you can create rules based on nothing populated. But for string fields NULL does not work and you have to reference like the code above.
Order Type can be pulled from the namespace “SoftPro.Select.Client.Enumerations”, but we do not see a reference for Title Company, to create the logic in the same manner.
Please let us know how we can pull Title Company from a namespace or how to reference a (Nothing) string.
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: C# (Nothing) String Reference

Post by BobRichards »

Sorry if this doesn't quite answer the question, but it is a little confusing. It also looks like you want a C# language answer?? If so then in the future, please post to the Integration Development forum.

1. When testing string fields for null or empty string, use String.IsNullOrEmpty(). It will return True if the string variable is null or if it contains a string of zero length.

2. The collection of Title Companies is available from the order. Just open the order and then inspect each title company.

Code: Select all

// Open order.
IOrder iOrder = os.OpenOrder(orderInfo);

// Get all Title Companies.
IList titleCompanies = (IList)iOrder.GetProperty("TitleCompanies");
if (titleCompanies.Count == 0)
{
	// List is empty.
}
else
{
	// Get the first Title Company.
	IOrderItem tc = (IOrderItem)titleCompanies[0];
	string name = (string)tc.GetProperty("Name");
	if (String.IsNullOrWhiteSpace(name))
	{
		// Name field is empty.
	}
}
Bob Richards, Senior Software Developer, SoftPro
johnpbzdon
Posts: 11
Joined: Mon May 09, 2016 10:07 am

Re: C# (Nothing) String Reference

Post by johnpbzdon »

Thanks for your reply Bob. Sorry for the confusion. After reviewing I was referring to the field “Title Office” {{Order.Title.Office}} on the “Order Information” screen and not a title company contact. We are trying to prevent users from entering in an “A” or “U” value in the field. I have the logic when a value is populated, but I’m getting pop up message “Object reference not set to instance of an object” when the value is empty. We want to accept an empty value or “T” value.

We are instantiating a title object, but don’t know how to determine an empty {{Order.Title.Office}} value.

IOrderItem title = (IOrderItem)iOrder["Title"];
johnpbzdon
Posts: 11
Joined: Mon May 09, 2016 10:07 am

Re: C# (Nothing) String Reference

Post by johnpbzdon »

As a side note I tried moving this post to the [Integration Development] > [Server] forum but I don’t have the rights. Please feel free to move the entire post if you can.
johnpbzdon
Posts: 11
Joined: Mon May 09, 2016 10:07 am

Re: C# (Nothing) String Reference

Post by johnpbzdon »

We were able to find a solution to our problem. One of our associates thought to use a Try Catch to capture the error. So if we don’t get the error then we know the title company exists, if we get the error it does not exist. Thanks again for your input.

int titleOfficeCount = 0;
String titleOffice = null;

//Check to see if Order Information: Title Office field has been set.
try
{ titleOffice = title["Office"].ToString;
titleOfficeCount = titleOfficeCount + 1; }
catch
{ titleOfficeCount = titleOfficeCount - 1; }
Post Reply