Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

P4 Server Administration Documentation | 2025.1

# Form-in triggers

Use the `form-in` trigger type to create triggers that fire when a user attempts to send a form to the server, but before the form is parsed by the P4 Server.

Example:

All users permitted to edit jobs have been placed in a designated group called `jobbers`. The following Python script runs p4 group `-o jobbers` with the `-G` (Python marshaled objects) flag to determine if the user who triggered the script is in the `jobbers` group.

Copy

    import sys, os, marshal

    # Configure for your environment
    tuser = "triggerman"   # trigger username
    job_group = "jobbers"  # Perforce group of users who may edit jobs

    # Get trigger input args
    user = sys.argv[1]

    # Get user list
    # Use global -G flag to get output as marshaled Python dictionary
    CMD = "p4 -G -u %s -p 1666 group -o %s" % \
            (tuser, job_group)
    result = {}
    result = marshal.load(os.popen(CMD, 'r'))

    job_users = []
    for k in result.keys():
            if k[:4] == 'User': # user key format: User0, User1, ...
                    u = result[k]
                    job_users.append(u)

    # Compare current user to job-editing users.
    if not user in job_users:
            print "\n\t>>> You don't have permission to edit jobs."
            print "\n\t>>> You must be a member of '%s'.\n" % job_group
            sys.exit(1)
    else: # user is in job_group -- OK to create/edit jobs
            sys.exit(0)

This `form-in` trigger fires on `job` forms only. To use the trigger, add the following line to the trigger table:

    sample8   form-in  job  "python jobgroup.py %user%"

If the user is in the `jobbers` group, the `form-in` trigger succeeds, and the changed job is passed to the P4 Server for parsing. Otherwise, an error message is displayed, and changes to the job are rejected.

For detailed guidance for using the flag for Python marshaled objects, see the Perforce Knowledge Base article, Using p4 -G.

Your search for returned results