Saturday, November 24, 2018

Set a Field Value Once Based on a Checkbox Selected via Workflow


This article identifies how to create a workflow that will set a fieldvalue based on a checkbox being selected. However, the value will only be set the very first time the checkbox isselected. (unless unchecked in the future).

In this use case: The user has an Alert Checkbox.  If the user selectsthis checkbox, the Alert Message field will display message: First Time AlertHas Been Set!.  The user then wantsother users to be able to manually change the Alert Message in the future,without it reverting back to the first time alert message.

    11. Create the Alert Check Box field to be used in the workflow.
            a.      Customization > Lists, Records, & Fields > Entity Fields > New
            b.      Label = Alert Checkbox
            c.      ID = _alertcheckbox
            d.      Type = Check Box
            e.      Store Value = Checked
            f.      Applies To = Customer
            g.      Display tab > Subtab = Main
            h.      Save

2.       2. Create the Alert Backup Check Box field to be used in the workflow.
            a.      Customization > Lists, Records, & Fields > Entity Fields > New
            b.      Label = Alert Backup Checkbox
            c.      ID = _alertbackupcheckbox
            d.      Type = Check Box
            e.      Store Value = Not Checked
            f.      Applies To = Customer
            g.      Save

3.       3. Create the Alert Message Text field.
            a.      Customization > Lists, Records, & Fields > Entity Fields > New
            b.      Label = Alert Message
            c.      ID = _alertmessage
            d.      Type = Free-Form Text
            e.      Store Value = Checked
            f.      Applies To = Customer
            g.      Display tab > Subtab = Main

4.       4. Create the Workflow
            a.      Customization > Scripting > Workflows > New
            b.      Name = Set Alert Message
            c.      Record Type = Customer
            d.      Sub Types = Customer
            e.      Execute as Admin = Checked
            f.      Release Status = Released
            g.      Event Based > On Create, On Update = Checked.
            h.      Save

5.       5. Create a new Workflow State
            a.      Click the New State button.
            b.      Name = State 1
            c.      Save

6.       6. Create a New Action to grab initial value of the Alert checkbox.
            a.      Select State 1
            b.      Actions tab > New Action > Set Field Value
            c.      Trigger On = Before User Edit
            d.      Condition > Visual Builder > Alert Checkbox = T
            e.      Parameters > Field = Alert Backup Checkbox
            f.      Value > Static Value > Checked = Checked
            g.      Save

7.       7. Create a New Action to set the Alert Message text field
            a.      Select State 1
            b.      Actions tab > New Action > Set Field Value
            c.      Trigger On = Before Record Submit
            d.      Condition > Custom Formula = ({custentity_alertbackupcheckbox.id} != {custentity_alertcheckbox.id}) and {custentity_alertcheckbox.id} = 'T'
            e.      Parameters > Field = Alert Message
            f.      Value > Static Value > Text = First Time Alert Has Been Set!
            g.      Save.

This workflow will allow a user to now Modify the Alert Message in the future, without it reverting to the first time Alert message due to the Alert Checkbox being checked.

Note: Additional workflow actions can be created with the condition that if the Alert Checkbox is True, to disable the Alert Checkbox to prevent users from un-checking, saving, then re-checking the checkbox in the future.

No comments:

Post a Comment