CopyRefObjDocuments
You can use the CopyRefObjDocuments function to automatically transfer document attachments (text, files, URLs) from a reference object to a newly created object.
Note: The two object types must have the same function code(s) assigned. This is commonly used in copy methods when creating objects from references.
When to use
You can use this function when:
- Creating a new object from a reference (for example specification from formula) and need to copy all attached documents.
- Copying documents from template objects to new instances, preserving documentation, procedures, and files.
When not to use
You cannot use this function when:
- The context attributes must not be inherited from the parent object.
- The function requires specific context setup and is outside of copy method workflows.
Syntax
long CopyRefObjDocuments();
Return Value
The application returns a value greater than zero (0) if the operation is successful.
Prerequisites
- The source and target objects must have matching function codes for document attachments.
- The function must be used in a copy method with reference object context.
Examples
- Example 1
-
Basic document copy
long ingred = CopyRefObjDocuments();
- Description
- This script is in a copy method for a specification that is created from the References tab of a formula (ObjectType = SPECIFICATION, Reference Type = FORMULA, Events = Create From As New). It copies all of the document attachments from the formula to the specification for function codes that are in common.
- Example 2
-
Copy with Property and Save
using System; using Formation.Shared.Defs; class ActionScript : FcProcFuncSetEventWF { public long wf_start() { try { object oDesc = ObjProperty("DESCRIPTION", CONTEXT._REFOBJECTSYMBOL, CONTEXT._REFOBJECTKEY); string descValue = oDesc != null ? oDesc.ToString() : ""; long lSetDesc = ObjPropertySet(descValue, 1L, "DESCRIPTION", "", ""); // Copy reference object's documents to the new object (copy method context) long lDoc = CopyRefObjDocuments(); MessageList($"ObjProperty returned: {(oDesc ?? "(null)")}"); MessageList($"ObjPropertySet result: {lSetDesc}"); MessageList($"CopyRefObjDocuments result: {lDoc}"); return 1; } catch (Exception ex) { MessageList("Error: " + ex.Message); return 0; } } } - Description
-
Copies the reference object's description into the new specification and performs a forced save before document operations.
All the documents are copied from the reference object to the specification and logs status codes for each step for auditing.