Advertising banner:
IF, ELSE, ENDIF  
Help Contents • Administration • FirstClass Scripting • Help Document
   
   
   
IF, ELSE, ENDIF
Examples



Function
These commands add logic flow to FC scripting. For every IF command, a matching ENDIF command must be included, if this is not the case the script will not be executed. For every IF command, 0 or 1 ELSE command is expected, if this is not the case the script will not be executed.
There is little value in creating IF commands just to avoid warning messages. For example, if you want to remove a folder from users desktops, but aren't sure whether the folder exists.  It is more effecient to write a script to remove the folder, even if it isn't there, than have FC scripting first check for its exsistence before deleting.
Or perhaps, you want to enable the unlisted feature on a number of User Info forms. Even if you suspect a few of the users already have unlisted enabled, it is far more efficient to simply enable the field for every user, than it is to first check the state of the checkbox. Your scripts will be much easier to write, and the server has to less work to do.



Syntax
IF expression test expression
        commands to execute if condition evaluates to true
ELSE
        commands to execute if condition evaluates to false
ENDIF
Parameters


OBJECT path EXISTS
Checks for the existence of a specified object.
OBJECT path MISSING
Checks whether a specified object is absent.
FIELD ID EXISTS
Field contains data on the form accompanying the script.
FIELD ID MISSING
Field doesn't contain data on the form accompanying the script.
FORMFIELD path FieldID EXISTS
Checks whether a field on any other form contains data.
FORMFIELD path FieldID MISSING
Checks whether a field on any other form doesn't contain data.
FIELD FieldID test FieldValue
Checks the contents of the field on the form accompanying the script against the specified pattern.
FIELD FieldID test FIELD FieldID
Compares the contents of two fields on the form accompanying the script.
FORMFIELD path FieldID test FieldValue
Checks the content of a field on any other form, defined by path.
test
For numeric comparison, one of the following:
<               less than
<=              less than or equal to
==              equal to
=!              not equal to
>=              greater than or equal to
>               greater than
path
The location of the object, relative to the administrator's Desktop. Separate the components of the path with colons (:). The PATHCHAR command can be used to change the default path character.
DESKTOP UserID path
An object on a user's Desktop. The path is relative to the user's Desktop.
FieldID
The field ID.
FieldValue
The value contained by the field. May be enclosed in quotes if needed. The field value must be numeric for Checkbox, Popup, and Number. Popup values can be found using FirstClass Designer.
MODIFIED
When an object was last modified:
MODIFIED BEFORE date
MODIFIED AFTER date
MODIFIED BETWEEN StartDate EndDate
MODIFIED OUTSIDE StartDate EndDate



Examples
With OBJECT
Before writing a complex script, you may find it helpful to start by confirming the IF command returns the expected results.
The following script will return a message containing either True or False, depending on the existence of Employee Lounge conference within General Conferences.
REPLY
IF OBJECT "General Conferences:Employee Lounge" EXISTS
        WRITE True
ELSE
        WRITE False
ENDIF
This simple step will eliminate the IF command when debugging your script. In this example, if False is returned, look syntax or typing errors.
Within Employee Lounge there is a Contact Database, and you want create an alias of this in all the Contacts folders of your sales staff.  You know that some Sales staff have already done this, but you want to make sure every team member has the Contact Database.  In addition, the name of the Contact Database had changed from Customers to East Coast Customers. So there are two issues to solve, renaming existing alias and creating an alias if one doesn't exist.
//Check to see if a user has an alias to Customers in the Contacts folder
IF OBJECT desktop sbram "Contacts:Customers" EXISTS
        // if the above statement is true then rename
        rename desktop sbram "Contacts:Customers" "East Coast Customers"
ELSE
        //if the above is false, create the alias.
LINK SPECIAL desktop sbram "Contacts" "General Conferences:Employee Lounge:East Coast Customers"
ENDIF
In this example, the result of the test will execute a script contained in document.
//Check to see if a user has an alias to Customers in the Contacts folder
IF OBJECT desktop sbram "Contacts:Customers" EXISTS
        // if the above statement is true run this script
EXECUTE SCRIPT PATH desktop admin "scripts:TrueContacts"
ELSE
        //if the above is false, run this script
EXECUTE SCRIPT PATH desktop admin "scripts:FalseContacts"
ENDIF
To repeat the commands based on a list of UserIDs see the REPEAT command.
With FORMFIELD
Your custom form contains a checkbox, field ID 1000, and depending on its fieldvalue, two different scripts will run.
IF FORMFIELD "General Conferences:Employee Lounge:Event form" 1000 == 1
        \\if value is equal to one execute the following commands
ELSE
        \\if value is not equal to 1, then execute the following commands
ENDIF
Your custom form contains a checkbox, field ID 1000, and if fieldvalue is equal to 1, than a script is executed. If the value is not equal to 1 then you want the script to terminate.
IF FORMFIELD "General Conferences:Employee Lounge:Event form" 1000 == 1
        \\if value is equal to one run execute the following commands
ELSE
        \\if value is not equal to 1, then stop processing commands here
        ENDSCRIPT
ENDIF
With FIELD
Users are presented with a form, that has an Editable Selection list, where Choose from list only is enabled. This has two choices: New Project; Copy Project. New Project is the default, therefore when the field is set to New Project, the field is missing because the server does not store default values of any form. The only time the field will have data, will be if Copy Project is choosen.
Any of the following commands can used:
IF FIELD 1000 EXISTS
        \\The field has data, so run the script that copies a project.
        EXECUTE SCRIPT path desktop admin "my scripts:copy project"
ELSE
        \\The field has no data, so run the script that creates a project.
EXECUTE SCRIPT path desktop admin "my scripts:new project"
ENDIF
or
IF FIELD 1000 MISSING
        \\The field has no data, so run the script that creates a project.
EXECUTE SCRIPT path desktop admin "my scripts:new project"      
ELSE
\\The field has data, so run the script that copies a project.
        EXECUTE SCRIPT path desktop admin "my scripts:copy project"
ENDIF
or
IF FIELD 1000 == Copy Project
        \\The field is equal to Copy Project, run the script that copies a project.
        EXECUTE SCRIPT path desktop admin "my scripts:copy project"
ELSE
        \\Field ID is not equal to Copy Project, so run the script that createa a project.
EXECUTE SCRIPT path desktop admin "my scripts:new project"      
ENDIF
06092010_122716_1.jpg        Note
If the form did not contain a field 1000, than the IF command would consider it missing.
The same form also has a field (Field ID 1001) where the Project name is entered, and you want the IF command to terminate if the form is missing the Projectname. This script uses nested IF commands.
IF FIELD 1001 MISSING
        REPLY
        WRITE The script did not run because the Project name is missing.
        ENDSCRIPT
ELSE
        ENABLEFIELDSUBSTITUTION
        NEW "general conferences:projects" "#1002" "" CONFERENCE 8 -1 -1 +p
        \\this part of the script contains the commands that determine group membership
IF FIELD 1002 == "private project"
        \\The field is equal to private project, so put the conference in the "Private Project" container group.
ELSE
        \\Field ID is not equal to private project, so put the conference in the "All Sales Team" container group.
ENDIF
ENDIF
Your script compares the value of a field on the form accompanying the script, and a field on another form.
IF FIELD 1000 == FORMFIELD "general conferences:employee lounge:Event form" 1001
With MODIFIED
IF Desktop Admin "www:templates" MODIFIED OUTSIDE 2011/10/01 2011/11/01
        WRITE Update not applicable
        RETURN
ENDIF



Related commands
EXPORT, ENABLEFIELDSUBSTITUTION, COPY, PGADD commands can be used to combined with IF to create custom workflow scripts.