A client recently asked if they could get the name of the contact’s referral partner to a custom field on the contact’s record. That is, if “John Smith” had been attributed as the referral partner responsible for brining in “Jane Parker” as a lead, they wanted “John Smith” to appear in a custom text field called “Referredby”. That field would then be synchronized to a different system being used for reporting and accounting.
Unfortunately the way Infusionsoft is structured, it’s not easy to get from the contact record to the referral partner’s record and vice versa. However, with Pocket Developer’s Any Text, Anywhere plugin and Advanced Merge Notation, we were able to do it with one HTTP Post. Here’s what we did.
First, we are going to go the the Referral table and retrieve the Affiliate Id we find there that is associated with the current contact’s Contact Id by using a “prefetch” (which we number 0, because order matters and we always start with 0):
prefetch[0][affid] = Referral.AffiliateId.FilterBy(ContactId:~Contact.Id~)
Here we are making “affid” the name for “the Affiliate Id you find on the Referral table when you filter it to look for the Contact Id that matches the current contact’s id”. (You could use any word-like string you want as long as you use the same name in the next value.)
Next, we are going to go to the Affilate table and retrieve the Contact Id we find there that is associated with the Affiliate Id we just prefetched. We’ll call it “conid”.
prefetch[1][conid] = Affiliate({affid}).ContactId
We only want to find one record, so right after the table name we add parentheses to contain the specific record we are looking for. We prefetched that affiliate number in the previous step, so we use the name we gave it — “affid” — inside brackets and put it inside the parentheses.
Now we have the contact id of the referral partner saved with the name “conid”. We want to get the first and last name of that contact id, so we want to go to the Contact table and find that specific record. Again, we’re going to use parentheses after the table name, with the specific number we are looking for inside those parentheses, to get the information we want:
prefetch[2][first] = Contact({conid}).FirstName
prefetch[3][last] = Contact({conid}).LastName
We finally have the first and last name, called “first” and “last”. Now we just have to tell AnyText what it should cope and where it should copy it to:
textToSave[0] = {first} {last}
saveTo[0] = Contact._Referredby
In this case, we’re saving the first and last name we prefetched into the Referredby custom field.
If we wanted to get additional information from the affiliate’s record, we would do additional prefetches (incrementing the number and naming each uniquely). And if we wanted to save to additional fields, we would add textToSave–saveTo pairings (incrementing the paired numbers).
And that’s it!