USP_BBNC_COMMITPROFILEUPDATEORGANIZATIONBIOGRAPHICAL

Updates an organization's biographical information from a Blackbaud Internet Solutions profile transaction to the system from a given batch.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN
@ORGNAME nvarchar(100) IN
@INDUSTRYCODEID uniqueidentifier IN
@WEBADDRESS UDT_WEBADDRESS IN
@CUSTOMIDENTIFIER nvarchar(36) IN
@NUMBEROFEMPLOYEES int IN
@NUMBEROFSUBSIDIARIES int IN
@REQUESTNOEMAIL bit IN
@CHANGEAGENTID uniqueidentifier IN
@CHANGEDATE datetime IN

Definition

Copy


            CREATE procedure dbo.USP_BBNC_COMMITPROFILEUPDATEORGANIZATIONBIOGRAPHICAL
            (
                @ID uniqueidentifier,
                @ORGNAME nvarchar(100),
                @INDUSTRYCODEID uniqueidentifier,
                @WEBADDRESS dbo.UDT_WEBADDRESS = '',
                @CUSTOMIDENTIFIER nvarchar(36) = '',
                @NUMBEROFEMPLOYEES int = 0,
                @NUMBEROFSUBSIDIARIES int = 0,
                @REQUESTNOEMAIL bit = 0,
                @CHANGEAGENTID uniqueidentifier,
                @CHANGEDATE datetime
            )
            as
            set nocount on;

                if @ID is null
                begin
                    raiserror('The constituent ID is required',16,1);
                    return -2;
                end

                if @CHANGEAGENTID is null
                    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;

                if @CHANGEDATE is null
                    set @CHANGEDATE = getdate();    

                if @NUMBEROFEMPLOYEES is null
                    set @NUMBEROFEMPLOYEES = 0;

                if @NUMBEROFSUBSIDIARIES is null
                    set @NUMBEROFSUBSIDIARIES = 0;

                begin try
                    update dbo.CONSTITUENT
                        set KEYNAME = @ORGNAME,
                            WEBADDRESS = @WEBADDRESS,
                            CUSTOMIDENTIFIER = @CUSTOMIDENTIFIER,
                            CHANGEDBYID = @CHANGEAGENTID,
                            DATECHANGED = @CHANGEDATE
                        where
                            ID = @ID;

                        if (select count(ID) from dbo.ORGANIZATIONDATA where ID = @ID) > 0
                        begin
                            update dbo.ORGANIZATIONDATA
                                set INDUSTRYCODEID = @INDUSTRYCODEID,
                                    NUMEMPLOYEES = @NUMBEROFEMPLOYEES,
                                    NUMSUBSIDIARIES = @NUMBEROFSUBSIDIARIES,
                                    CHANGEDBYID = @CHANGEAGENTID,
                                    DATECHANGED = @CHANGEDATE
                                where ID = @ID;
                        end
                        else
                        begin
                            insert into dbo.ORGANIZATIONDATA(ID, INDUSTRYCODEID, NUMEMPLOYEES, NUMSUBSIDIARIES, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
                                values(@ID, @INDUSTRYCODEID, @NUMBEROFEMPLOYEES, @NUMBEROFSUBSIDIARIES, @CHANGEAGENTID, @CHANGEAGENTID, @CHANGEDATE, @CHANGEDATE);
                        end

                        --Retrieve the ID of the solicit code being used to flag do not email.

                        declare @NOEMAILSOLICITCODEID uniqueidentifier
                        select top 1 @NOEMAILSOLICITCODEID=DONOTEMAILSOLICITCODEID
                        from NETCOMMUNITYDEFAULTCODEMAP

                        --Does the constituent already have that solicit code assigned?

                        declare @CONSTITUENTSOLICITCODEID uniqueidentifier
                        select @CONSTITUENTSOLICITCODEID=ID 
                        from CONSTITUENTSOLICITCODE 
                        where CONSTITUENTID=@ID and 
                            SOLICITCODEID=@NOEMAILSOLICITCODEID

                        --If they request to not receive email...

                        if @REQUESTNOEMAIL = 1 
                        begin
                            --And if they don't have the appropriate solicit code, add it.

                            if @CONSTITUENTSOLICITCODEID is null
                            begin
                                exec dbo.USP_DATAFORM_ADD_CONSTITUENTSOLICITCODE null, @NOEMAILSOLICITCODEID, @ID, null, null, '', @CHANGEAGENTID
                            end
                            --Otherwise, if they do have the solicit code and the dates on the code do not include today, 

                            --  unbound its date range.

                            else
                            begin
                                update CONSTITUENTSOLICITCODE
                                set
                                    STARTDATE=null,
                                    ENDDATE=null,
                                    CHANGEDBYID=@CHANGEAGENTID,
                                    DATECHANGED=@CHANGEDATE
                                where
                                    ID=@CONSTITUENTSOLICITCODEID and
                                    (((not STARTDATE is null) and (datediff(day, STARTDATE, getdate())<0)) or
                                    ((not ENDDATE is null) and (datediff(day, getdate(), ENDDATE)<0)))
                            end
                        end

                        --If they request to receive email and have the solicit code, remove it.

                        if @REQUESTNOEMAIL = 0 and not @CONSTITUENTSOLICITCODEID is null
                        begin
                            exec dbo.USP_CONSTITUENTSOLICITCODE_DELETE @CONSTITUENTSOLICITCODEID, @CHANGEAGENTID
                        end
                end try
                begin catch
                    exec dbo.USP_RAISE_ERROR;
                    return 1;
                end catch

                return 0;