LinkIDMAttachments

You can use the LinkIDMAttachments function to link existing IDM attachments from a source object to a target object. You can specify the function code and the file or files to link between the objects.

When to use

You can use this function to:

  • Automatically link documents from source objects to newly created objects.
  • Share attachments between related objects.
  • Link existing attachments instead of creating duplicate file attachments.

When not to use

You cannot use this function to upload new files.

Syntax

Parameter Type required Description
targetSymbol(objSymbol) string Yes The Optiva object symbol to which you want to link the attachment. For example,"FORMULA", "ITEM"
targetCode(objKey) string Yes The Optiva object code to which you want to link the attachment. For example "ITEM001", "FORMULA1\0001"
sourceSymbol(refSymbol) string Yes The Optiva object Symbol that already has the attachment. for example, "FORMULA", "ITEM")
sourceCode(refKey) string Yes The Optiva object code that already has the attachment. For example, "ITEM001", "FORMULA1\0001"
functionCode string Yes IDM Doc Code to which the file is already attached in the source object
filename string or List Yes

The name of the file that you want to link between the source and target object. For example "sample.jpg","test.txt".

Note: Include the file extension in the file name.

For a single file, specify a string for the file name. For multiple files, specify a list of file names, including the file extensions.

offset int No By default the value is 0. Offset for pagination. The starting index for the object search.
limit int No By default the value is 1000. The maximum number of records you can search using the value specified in the offset.

Return Value

The application returns a value one (1) if the operation is successful and zero (0) if an error occurs.

Prerequisites

Standard IDM access is required. No additional permissions are required.

Examples

Example 1
Link Attachments from item to formula.
using System;
using System.Collections.Generic;
using Formation.Shared.Defs;

class ActionScript : FcProcFuncSetEventWF
{
    public long wf_approve()
    {
        try
        {
            // 1) Generate a new code for the formula
            string sformCode = GenerateCodeNumber("NEW FORMULA");

            // 2) Check whether the generated code already exists
            int exists = ObjectExists(sformCode, "FORMULA");
            if (exists == 1)
            {
                MessageList("Formula already exists.");
                return 111L;
            }

            // 3) Create a copy of TEMPLATE using the generated code
            // ObjectSaveAs signature: long ObjectSaveAs(string objSymbol, string objKey, ref string newKey)
            string newKey = sformCode;
            long saveStatus = ObjectSaveAs("FORMULA", "TEMPLATE", ref newKey);

            if (saveStatus >= 0)
            {
                // 4) Open the new formula form
                StartForm("frmformula", newKey);

                // 5) Attach a single file
                int linkStatus = LinkIDMAttachments(
                    "FORMULA",        // target symbol
                    newKey,           // target key
                    "FORMULA",        // source symbol (as used in original)
                    "REPL001\\0001",  // source key (escaped backslash)
                    "ATTACH_DOCUMENTS_TEST",
                    "samplepic.jpg"   // single file
                );

                if (linkStatus == 1)
                    MessageList("Attachment is linked to object Successfully");
                else
                    MessageList("Error in linking Attachment to Object");

                // 6) Attach multiple files
                var files = new List<string> { "desert.jpg", "samplepic1.jpg" };
                linkStatus = LinkIDMAttachments(
                    "FORMULA",
                    newKey,
                    "FORMULA",
                    "REPL001\\0001",
                    "ATTACH_DOCUMENTS_TEST",
                    files
                );

                if (linkStatus == 1)
                    MessageList("Attachments are linked to object Successfully");
                else
                    MessageList("Error in linking Attachments to Object");
            }
            else
            {
                MessageList(newKey + " was not created.");
            }
        }
        catch (Exception ex)
        {
            MessageList("Error in wf_approve: " + ex.Message);
        }

        return 111L;
    }
}
Description
This example shows you how to create a formula, REPL001\0001, and link documents from an existing item 00001 to the new formula. A value of 1 is returned when the process is successful.
Example 2
Attach IDM files to the current object using LinkIDMAttachments.
Example 2 : Attach IDM file(s) to the current object using LinkIDMAttachments
using System;
using System.Diagnostics;

class ActionScript : FcProcFuncSetEventWF
{
    public long wf_start()
    {
        // LinkIDMAttachments(targetSymbol, targetCode, sourceSymbol, sourceCode, functionCode, filename(s), offset, limit)
        int linkStatus = LinkIDMAttachments(_OBJECTSYMBOL, _OBJECTKEY,
                                            "ITEM", "ITEM4",
                                            "IDM_TEST", "Lion.jpg",
                                            0, 1000);

        if (linkStatus == 1)
            MessageList("Attachments are linked to object Successfully.");
        else if (linkStatus == 0)
            MessageList("Some or no attachments are linked.");
        else
            MessageList("Error in linking Attachment to Object.");

        MessageList("Attaching Single files");

        return 111L;
    }
}
Description
This example shows how to attach the IDM file "Lion.jpg" from source ITEM/ITEM4 to the current object (_OBJECTSYMBOL/_OBJECTKEY) using function code "IDM_TEST" with paging (offset=0, limit=1000) and logs a concise status.
Example 3
Attach IDM documents to the current workflow object (FsLibIDMHelper + LinkIDMAttachments).
using System;
using Formation.Shared.Defs;
using Infor.DocumentManagement.ICP; // adjust namespace as needed

class ActionScript : FcProcFuncSetEventWF
{
    public long wf_start()
    {
        // Inputs
        string symbol = "ITEM";
        string objCode = "ITEM75";
        string fileName = "Tiger.jpg"; // unused in this example; used if filtering by name

        // Build IDM query (escape quotes)
        string sQry = "/IDM_TEST[@OPTIVA_SYMBOL = \"" + symbol + "\" AND @OPTIVA_SYMBOL_ID = \"" + objCode + "\"]";

        try
        {
            // Create IDM helper and retrieve documents as CMItems
            var idmHelper = new FsLibIDMHelper(this);
            CMItems cMItems = idmHelper.GetDocuments(sQry);

            if (cMItems == null)
            {
                MessageList("No documents returned from IDM for query: " + sQry);
                return 0;
            }

            // Link documents to the current workflow object
            int linkStatus = LinkIDMAttachments(cMItems, _OBJECTSYMBOL, _OBJECTKEY);

            if (linkStatus == 1)
                MessageList("Attachments are linked to object Successfully.");
            else if (linkStatus == 0)
                MessageList("Some or no attachments are linked.");
            else
                MessageList("Error in linking Attachment to Object. LinkIDMAttachments returned: " + linkStatus);

            return 111L;
        }
        catch (Exception ex)
        {
            MessageList("Exception in wf_start: " + ex.Message);
            PublishDebuggingInfo("wf_start exception: " + ex.ToString(), "ERROR");
            return -1;
        }
    }
}
Description
This example builds an IDM query for documents associated with a specific symbol/key, retrieve the documents into a CMItems collection with FsLibIDMHelper.GetDocuments(sQry), then call LinkIDMAttachments(cMItems, targetSymbol, targetKey) to link them to the current workflow object.