USP_DATAFORMTEMPLATE_EDITLOAD_EXTENDEDRELATIONSHIP_PFLINKINDTOCONSTIT

The load procedure used by the edit dataform template "Extended Relationship Private Foundation Link Individual To Constituent Edit Data Form"

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter used to load the fields defined on the form.
@DATALOADED bit INOUT Output parameter indicating whether or not data was actually loaded.
@TSLONG bigint INOUT Output parameter indicating the TSLONG value of the record being edited. This is used to manage multi-user concurrency issues when multiple users access the same record.
@CONSTITUENTID uniqueidentifier INOUT Related individual
@LASTNAME nvarchar(100) INOUT Last name
@FIRSTNAME nvarchar(50) INOUT First name
@MIDDLENAME nvarchar(50) INOUT Middle name
@SUFFIXCODEID uniqueidentifier INOUT Suffix
@TITLECODEID uniqueidentifier INOUT Title
@YEAROFBIRTH UDT_YEAR INOUT Year of birth
@GENDERCODE tinyint INOUT Gender
@ADDRESS nvarchar(100) INOUT Address
@CITY nvarchar(50) INOUT City
@STATEID uniqueidentifier INOUT State 1
@ZIP nvarchar(10) INOUT Zip
@B_ADDRESS nvarchar(100) INOUT Business address
@B_CITY nvarchar(50) INOUT Business city
@B_STATEID uniqueidentifier INOUT Business state
@B_ZIP nvarchar(10) INOUT Business zip
@B_ID uniqueidentifier INOUT Business ID
@B_NAME nvarchar(100) INOUT Business name
@B_PHONE nvarchar(20) INOUT Business phone
@B_WEBSITE UDT_WEBADDRESS INOUT Business website
@POSITION nvarchar(30) INOUT Job title
@CONSTITUENTNAME nvarchar(200) INOUT Constituent name
@INFOSOURCECODEID uniqueidentifier INOUT Info source code

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDITLOAD_EXTENDEDRELATIONSHIP_PFLINKINDTOCONSTIT(
    @ID uniqueidentifier,
    @DATALOADED bit = 0 output,
    @TSLONG bigint = 0 output,
    @CONSTITUENTID uniqueidentifier = null output,
    @LASTNAME nvarchar(100) = null output,
    @FIRSTNAME nvarchar(50) = null output,
    @MIDDLENAME nvarchar(50) = null output,
    @SUFFIXCODEID uniqueidentifier = null output,
    @TITLECODEID uniqueidentifier = null output,
    @YEAROFBIRTH dbo.UDT_YEAR = null output,
    @GENDERCODE tinyint = null output,
    @ADDRESS nvarchar(100) = null output,
    @CITY nvarchar(50) = null output,
    @STATEID uniqueidentifier = null output,
    @ZIP nvarchar(10) = null output,
    @B_ADDRESS nvarchar(100) = null output,
    @B_CITY nvarchar(50) = null output,
    @B_STATEID uniqueidentifier = null output,
    @B_ZIP nvarchar(10) = null output,
    @B_ID uniqueidentifier = null output,
    @B_NAME nvarchar(100) = null output,
    @B_PHONE nvarchar(20) = null output,
    @B_WEBSITE dbo.UDT_WEBADDRESS = null output,
    @POSITION nvarchar(30) = null output,
    @CONSTITUENTNAME nvarchar(200) = null output,
    @INFOSOURCECODEID uniqueidentifier = null output
)
as

    set nocount on;

    declare @CHANGEAGENTID uniqueidentifier
    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

    declare @CURRENTDATE datetime
    set @CURRENTDATE = getdate()

    declare @DEFAULTCOUNTRYID uniqueidentifier;
    exec @DEFAULTCOUNTRYID = dbo.UFN_COUNTRY_GETDEFAULT;

    -- be sure to set these, in case the select returns no rows

    set @DATALOADED = 0
    set @TSLONG = 0

    -- populate the output parameters, which correspond to fields on the form.  Note that

    -- we set @DATALOADED = 1 to indicate that the load was successful.  Otherwise, the system

    -- will display a "no data loaded" message.  Also note that we fetch the TSLONG so that concurrency

    -- can be considered.

    select
        @DATALOADED = 1,
        @TSLONG = IND.TSLONG,
        @CONSTITUENTID = IND.CONSTITUENTID,
        @CONSTITUENTNAME = IND.FULLNAME,
        @LASTNAME = IND.LASTNAME,
        @FIRSTNAME = IND.FIRSTNAME,
        @MIDDLENAME = IND.MIDDLE,
        --@SUFFIXCODEID = (select ID from dbo.SUFFIXCODE where DESCRIPTION like IND.SUFFIX,

        @POSITION = IND.TITLE,
        --@ADDRESS = IND.ADDRESS,

        @CITY = IND.CITY,
        @STATEID = (select top(1) ID from dbo.STATE where COUNTRYID = @DEFAULTCOUNTRYID and (ABBREVIATION = coalesce(IND.STATE, '') or DESCRIPTION = coalesce(IND.STATE, ''))),
        @ZIP = IND.ZIP,
        @B_ID = REL.CONSTITUENTID,
        @B_ADDRESS = PF.LINE1,
        @B_CITY = PF.CITY,
        @B_STATEID = (select top(1) ID from dbo.STATE where COUNTRYID = @DEFAULTCOUNTRYID and (DESCRIPTION = coalesce(PF.STATE, '') or ABBREVIATION = coalesce(PF.STATE, ''))),
        @B_ZIP = PF.ZIP,
        @B_NAME = PF.COMPANY,
        @B_PHONE = PF.PHONE,
        @B_WEBSITE = PF.WEBSITE
    from 
        dbo.WPRELATIONSHIP_PF_IND IND
    join
        dbo.WPRELATIONSHIP_PF REL on REL.ID = IND.WPRELATIONSHIP_PF_ID
    join
        dbo.WPPRIVATEFOUNDATION PF on PF.WPRELATIONSHIP_PF_ID = REL.ID
    where 
        IND.ID = @ID

    select @INFOSOURCECODEID = ID from dbo.INFOSOURCECODE where DESCRIPTION = 'GuideStar'
    if @INFOSOURCECODEID is null begin
        insert into dbo.INFOSOURCECODE
        (
            DESCRIPTION,
            ADDEDBYID,
            CHANGEDBYID,
            DATEADDED,
            DATECHANGED
        )
        values
        (
            'GuideStar',
            @CHANGEAGENTID,
            @CHANGEAGENTID,
            @CURRENTDATE,
            @CURRENTDATE
        )
        select @INFOSOURCECODEID = ID from dbo.INFOSOURCECODE where DESCRIPTION = 'GuideStar'
    end

return 0;