Domino Code Fragment

Code Name*
Approve Workflow Button
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.140.185.170
Description*
This formula is a short illustration of a very powerful technique. Suppose you have several routing steps in a workflow application. Each step may have very similar fields and buttons, but of course Notes formulas do not have subroutines to generalize functionality. Here we get our specific stuff out of the way at the top, and have generic code the rest of the way. Thus when you change the way the formula works, you don't have to copy the code, and then go through the painstaking and error-prone process of adapting essentially the same formula to the different sections of code. This sample is based on the approach that there are a number of sets of fields, each essentially the same, where each fieldname ends in an ordinal number, 1, 2, 3, etc., corresponding to the position of the set.
Type*
Formula
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
REM "This specific sample is for the APPROVE button for routing step 3.";
REM "Note: This is much simpler than typical code you would write.";
REM;
REM;
REM "Code specific to this routing step goes here.";
stepnum := 3;
stepnumtext := "3";
status := Status3;
comment := Comment3;
REM "Refer to these step-specific fields with the FIELD keyword to ensure @SetField works below.";

FIELD Approved3 := Approved3;
FIELD ApprovedDate3 := ApprovedDate3;
FIELD ApprovedBy3 := ApprovedBy3;
REM;
REM "Generic code for all steps follows below.";
REM;
title := "Approve Step " + stepnumtext;
@If(
status != "Complete";
@Do(
@Prompt([ok]; title; "You cannot approve a step which has not been marked Complete"; ""; "" );
@Return("")
);
@Success
);
REM;
@If(
@Trim(comment) = "";
@Do(
@Prompt([ok]; title; "You cannot approve this step without first entering a comment."; ""; "" );
@Return("")
);
@Success
);
REM;
yesno := @prompt([yesno]; title; "Are you sure you are ready to approve Step " + stepnumtext + "? All requirements must be met."; ""; "" );
@If(
yesno;
@Success;
@Return("")
);
REM;
REM "The trick now is to use the fact that @Setfield allows you to QUOTE the field name.";
REM;
@SetField( "Approved" + stepnumtext; "Approved" );
@SetField( "ApprovedDate" + stepnumtext; @Now );
@SetField( "ApprovedBy" + stepnumtext; @Name([cn]; @Username) );
REM;
REM "Special code: if this is the last step (4), the document now has final approval.";

FIELD DocumentApproval :=
@If(
stepnum = 4;
"Approved";
DocumentApproval
);