Formula to extract Main Person from BillTo Contact

Discussions related to custom development with Select.
Post Reply
B_Hinote
Posts: 57
Joined: Tue Jan 08, 2019 7:20 pm

Formula to extract Main Person from BillTo Contact

Post by B_Hinote »

I was trying to create a formula that would auto assign the Main Person associated with the BillTo Contact assigned to an invoice. (i.e. {{Order.Invoices.BillTo.People.Name}})
However, I am receiving the error (Invalid cast from 'System.String' to 'Person').

Is there a way to get around this?

Code: Select all

// Set Contact to main person
If ( CountOf({{.BillTo.People}})>=1 ) Then					
	Iterate {{.BillTo.People}} From 1 To #{{.BillTo.People}}				
		If ( @.IsMainPerson = True ) Then 			
			Value = @.Name
			Break		
		EndIf			
	Loop				
EndIf
Thank you
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Formula to extract Main Person from BillTo Contact

Post by BobRichards »

Try to use the Field Code Browser to look at the types of the objects you are using. The ultimate goal is the set the BillTo MainPerson and the type of that field is "Person". As the error message stated (and can be confirmed in the FCB), @.Name is of type "String" so they are not similar types.

To get the entire "Person" object instead of just the name, try setting "Value = @.Self" in your code.
Bob Richards, Senior Software Developer, SoftPro
Post Reply