[OGo-Users] Print the location address instead of mail address in formletters

Adam Tauno Williams users@opengroupware.org
Wed, 23 Jan 2008 12:11:22 -0500


--=-TGOdaoVjc4vGroOBcAqc
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

> As far as I know, OGo always use mailing address for the form letters of=20
> your contacts.
> If your contact is linked to an enterprise, the address used is the=20
> billing address.
> I have not seen yet a Default to override this. Thus, I have to ensure=20
> that the mailing address is filled in all my contacts.

It is a little complicated, but I don't believe anything is hardcoded.

OGoFormLetterAction from the WebUI looks like it uses
SkyAddressConverterDataSource from the DocumentAPI to get the data,
SkyAddressConverterDataSource in turn calls address:convert

    result =3D [self->context runCommand:@"address::convert",
                  @"type", type,  <--- formLetter / vCard
                  @"kind", kind,  <--- winword, etc...
                  @"ids", ids,
                  @"forkExport", [NSNumber numberWithBool:YES],
                  @"labels",  self->labels , nil];

In Logic/LSAddress/commands.plist maps "convert" to
LSAddressConverterCommand

That in turn uses the address::build-converter-data command to create a
"data converter".  It sure looks like this is the command that actually
does all the work...

/* inside address::convert */
data =3D [self _buildConverterDataOfType:self->type
             kind:self->kind
             primaryKeys:
               [self->ids map:@selector(valueForKey:) with:@"companyId"]
             labels:self->labels
             entityName:entityName
             inContext:_context];
....
[response setContent:data];

Inside address::build-converter-data it looks like all the formletter
fun happens in the _createFormLetterDataInCtx method.  In there the data
gets looped for each field specified in the form letter format [which is
a user default - you can set them in the webui or global domain with the
Defaults command,  the ones on the website are merely the defaults that
exist if you don't define any].  Keys are converted into values for each
key/object by calling -
  (NSString *)_getObj:(id)_obj forKey:(NSString *)_key
keys are broken up by the "." delimiter so "fred.smith.jane" becomes the
keypath object["fred"]["smith"]["jane"]

It isn't obvious how anything ends up in toAddress....  until I realized
that address::build-converter-data calls address::fetchAttributes and
this explicitly sets the "primary address" (eh?) to the key
"toAddress" (LSAddressFetchAttributesCommand.m in
fetchRequiredAttributesForKeys).  Primary address is determined by -

  if ([[_entity name] isEqualToString:@"Enterprise"])
    addrKind =3D @"bill";
  else if ([[_entity name] isEqualToString:@"Person"])
    addrKind =3D @"mailing";

So you should be able to specify the specific address in a formletter by
using the address kind instead of "toAddress" and get the value you
want.

Like -=20
formletter_kinds =3D ("myForm");
LSEnterpriseFormLetter =3D {
  myForm =3D (
      { key =3D "ship.name1";      suffix =3D "\n";             },
      { key =3D "ship.name2";      suffix =3D "\n";             },
      { key =3D "ship.name3";      suffix =3D "\n";             },
      { key =3D "ship.street";     suffix =3D "\n";             },
      { key =3D "ship.zip";        suffix =3D " ";              },
      { key =3D "ship.city";       suffix =3D "\n\n\n\n\n\n\n"; },
      { key =3D "toPerson.salutation";  suffix =3D " ";              },
      { key =3D "toPerson.name";        suffix =3D ",\n\n";          }
    );
 - for example.

Note that I haven't tried this, which is why it isn't in WMOGAG
[everything documented in WMOGAG is something I have seen work with my
own eyes]. =20

Setting defaults with the Defaults command is documented in WMOGAG.
http://docs.opengroupware.org/Members/whitemice/wmogag/

> >> http://www.google.de/search?q=3DOGo+formletter+configuration
> > http://opengroupware.org/en/users/docs/snippets/Configurations/Formlett=
ers.html=20
> > http://docs.opengroupware.org/Members/helge/Configurations/Address%20De=
faults=20


--=-TGOdaoVjc4vGroOBcAqc
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)

iD8DBQBHl3U6LRePpNle04MRAjO5AJ9LecJqsknep1Pflcc4PoSS5xXR3wCeKFdN
JJxSnlu1WjBbEM9JmvtqfrU=
=NJov
-----END PGP SIGNATURE-----

--=-TGOdaoVjc4vGroOBcAqc--