How to ensure workflow is triggered when a new rec...
# ask-stanley-ai
n
How to ensure workflow is triggered when a new record is created using "Make a Copy" functionality?
c
AI generated answer (using internal Slack threads):
To ensure a workflow is triggered when a new record is created using the "Make a Copy" functionality, you can use a combination of SuiteScript and workflows. Here are the steps: 1. Create a custom field that will be used to mark a record as a copy. This field can be hidden from the user interface to prevent manual changes. 2. Create a User Event script that triggers on the
pageInit
event. In this script, check if the context is "COPY". If it is, set the custom field created in step 1 to a specific value (e.g., "Yes" or "Copy"). Here's a sample code snippet:
Copy code
javascript
function pageInit(scriptContext) {
    if (scriptContext.type === scriptContext.UserEventType.COPY) {
        scriptContext.newRecord.setValue({
            fieldId: 'custrecord_is_copy', // replace with your custom field ID
            value: 'Yes'
        });
    }
}
3. Create a workflow that triggers on record creation. In the initial state of the workflow, add a condition to check if the custom field is set to the specific value. If it is, proceed with the workflow actions. If not, end the workflow. 4. Make sure to set the workflow to trigger 'on view or update' to ensure it runs when a record is copied. Remember to deploy the User Event script and activate the workflow. Now, whenever a record is copied, the script will mark it as a copy, and the workflow will be triggered. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.852763116
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840781808
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.82952261
Please provide your feedback on this answer.