Copy Method Scripts

Example 1
Copymethod script to add Add ITEM_TEMP_DK set code to current object.
using System;
using Formation.Shared.Defs;

class CopyScript : FcProcFuncSetEventWF
{
    public long wf_start()
    {
        try
        {
            string objSymbol = "";              // current workflow object
            string objKey = "";                 // current workflow object
            string setCode = "ITEM_TEMP_DK";    // set code to add

            // Add the set code (params string[])
            long rc = AddSetCodes(objSymbol, objKey, setCode);

            if (rc > 0)
            {
                MessageList($"Successfully added set code '{setCode}' (rc={rc}).");
                return 1;
            }
            else
            {
                MessageList($"Failed to add set code '{setCode}' (rc={rc}).");
                return 0;
            }
        }
        catch (Exception ex)
        {
            MessageList("Error in AddSetCodes workflow: " + ex.Message);
            return 0;
        }
    }
}
Example 2
Copymethod script to perform a multi-step copy from a reference object .
  1. Copies context attributes, set codes, references, ingredients, and technical parameters (via CopyMethod.CopyRefObjTechParams).
  2. logging success or failure for each step with the MessageList.
using System;
using System.Diagnostics;

public class CopyScript : FcProcFuncSetEventCopyMethod
{
    public long Execute()
    {
        long rtnVal = 0;

        try
        {
            // 1. Copy Context Attributes
            rtnVal = CopyRefObjContextAttrib();
            MessageList(rtnVal == 0
                ? "Context Attributes copied successfully."
                : $"Failed to copy Context Attributes. RC={rtnVal}");

            // 2. Copy Set Codes
            rtnVal = CopyRefObjSetCodes();
            MessageList(rtnVal == 0
                ? "Set Codes copied successfully."
                : $"Failed to copy Set Codes. RC={rtnVal}");

            // 3. Copy References
            rtnVal = CopyRefObjReferences();
            MessageList(rtnVal == 0
                ? "References copied successfully."
                : $"Failed to copy References. RC={rtnVal}");

            // 4. Copy Ingredients
            rtnVal = CopyRefObjIngreds();
            MessageList(rtnVal == 0
                ? "Ingredients copied successfully."
                : $"Failed to copy Ingredients. RC={rtnVal}");

            // 5. Copy Technical Parameters (wrapped in its own try/catch to mirror the VB)
            try
            {
                object oParam = CopyMethod.CopyRefObjTechParams();
                MessageList("Copied Parameters from Formula");
            }
            catch (Exception ex)
            {
                MessageList(ex.ToString());
            }
        }
        catch (Exception ex)
        {
            MessageList("Exception in Execute: " + ex.ToString());
            rtnVal = 9111;
        }

        return rtnVal;
    }
}