Setting warning messages on batch validation on a custom batch

Hi all, I'm trying to figure out how to raise a warning on batch validation. Not an error, just a warning. I can't find this documented anywhere.

Comments

  • We add a user message to the specific batch table that we are working with using its store procedure.

    For example, if I am working with the constituent update table and I want to add an informational message to a constituent's record, I will call the USP_BATCHCONSTITUENTUPDATEBATCHUSERMESSAGE_ADD stored procedure (usually from within the AfterFileImport() method in the import handler). You will need to pass 3 parameters into this stored procedure: BATCHCONSTITUENTUPDATEID, MESSAGETEXT, and CHANGEAGENTID.

    Within the batch, the user can decide what to do with the message because it will stop the batch from committing ("Clear row message" or “Clear all”).

    Hope this helps,

    Matt

    54267b88598fdd55287ae8534f500185-origina
  • So I was trying to use the SYSTEMMESSAGES stored proc but I have switched to USERMESSAGES and it's still not working.

    Here's my code… this is in my commit add form. (Damn, I can't seem to format as code anymore in this.. sigh)

    I have verified that it successfully raises the warning as an error when RAISERROR is not commented out. I've also verified that @USR_UNC_BATCHSTUDENTIMPORTID contains the expected value. However, no row is inserted into the user messages table nor is any row visible. I feel like “successful” validation is wiping out all messages.

    IF LEN(@warnings) > 0
    BEGIN
    SET @warnings = convert(nvarchar(max),@USR_UNC_BATCHSTUDENTIMPORTID) + ' ' + @warnings
    – RAISERROR(@warnings,16,3)
    exec dbo.USP_USR_UNC_BATCHSTUDENTIMPORTBATCHUSERMESSAGE_ADD
    @USR_UNC_BATCHSTUDENTIMPORTID,
    @warnings,
    @CHANGEAGENTID
    END
    IF @VALIDATEONLY = 1
    RETURN 0

  • Well a couple of things for us, at least. If you use the RAISERROR before you execute the stored procedure, it will roll everything back (actually tested that and it would not run the stored procedure at all - but if I commented the stored procedure, then it would run the stored procedure). The other problem that at least we had with executing this stored procedure in the COMMIT section of a batch is that Blackbaud's commit code runs first, then your code in the commit section will run. So, if the batch is successfully committed and even if the record is added to the table, since the batch has already been committed, the user message will not display in the batch. It will be added to the USER MESSAGE table, but we have found that because Blackbaud's code runs first, the batch will be committed BEFORE our code runs and the record(s) will be added to the USER MESSAGE table, but by that time, it really is irrelevant because the batch has already been committed and the message will not display in the batch. We use the USER MESSAGE table during the ADD section in the or in the import handler. You might be able to also run it as an operation BEFORE the Commit button, but we have not tested that, yet. We ended creating a ‘Validate’ button so that we could run processes BEFORE the user hits the COMMIT button because we wanted to run processes before Blackbaud runs their commit process.

    1fb5e4f3a2ea9ff9afbb5f0013611330-origina
  • Matthew, that's really interesting.

    I want to use the “VALIDATEONLY” portion of the commit so I can press the “Validate” button in the batch itself.

    However, if you don't RAISERROR, it seems that Blackbaud actually decides there are no validation errors and erases all items with an ORIGINCODE of “validation” from the BATCHSYSTEMMESSAGES table. So you can't insert warnings or errors that way.

    I have been able to successfully add warnings and errors in my Add Form, and if I use an ORIGINCODE of “Import”, the messages show the “dismiss” option and are NOT wiped out by validation.

    Still, it would be nice if this stuff were documented, wouldn't it?

    This does give me an idea, I'll have to see if I can raise errors and warnings with a source of “Import” in the commit form when VALIDATEONLY=1….