Skip to main content
Question

Macro does not execute in IFS Cloud

  • Dec 3, 2026 12:17 PM UTC
  • 1 reply
  • 15 views

Forum|alt.badge.img+7

Hola ​@Mathias Dahl

 ​​​I’ve seen in the community that you’re an expert in macros!!!

I have created a macro in IFS Cloud to add the string ‘CODDOC-’ and the document revision no to the Word document that is downloaded. Steps:

  1. Document Macro Block: I create the macro:
    1. Public Sub AppendCODDOC_AtEnd()
          MsgBox (Run AppendCODDOC_AtEnd)
          Dim filename, wdApp, wdDoc, nrodoc
          filename = Replace(ClientScriptValues.Item("LOCAL_FILE_1").Value, "/", "\")
          Set wdApp = CreateObject("Word.Application")
         wdApp.Visible = True
          Set wdDoc = wdApp.Documents.Open(filename)
          nrodoc = CStr(ScriptValues.Item("DOC_NO").Value)
          ' Ir al inicio
          wdApp.Selection.HomeKey 6  ' wdStory
          ' Insertar texto
          wdApp.Selection.TypeText "CODDOC-" & nrodoc
          wdApp.Selection.TypeParagraph
          ' Volver al inicio y seleccionar la línea insertada
          wdApp.Selection.HomeKey 6
          wdApp.Selection.EndKey 5  ' wdLine
          wdApp.Selection.MoveLeft 1, Len("CODDOC-" & nrodoc), 1  ' Seleccionar
           ' Aplicar color blanco
          wdApp.Selection.Font.Color = 16777215
          wdApp.Selection.Font.Size = 1
           ' Deseleccionar
          wdApp.Selection.HomeKey 6
          wdDoc.Save

      End Sub

  1. I crete the File Type (WORDM)
  1. Document Macros
  1. Document Class Management, on Macros tab, I created the process Checkout with WORDM File type.
  1. Document Class Management, on Format tab, I create the format: EJEC01
  1. Document File Template for the EJEC01 format
  1. The document I need to attach, for example in Functional Object, is a document saved as a template.
  2. In Functional Object, I attach a new document using a template
  3. I’ve downloaded the macro to edit it, but it doesn’t seem to be running because neither the word ‘CODDOC-’ appears nor is the message (MagBox) displayed (the document doesn’t open automatically; it downloads to the ‘Downloads’ folder and I open it manually).

IFS Cloud 24R2, Edge navigator and with Aurena Agent active (but I don’t know if the problem is the Aurena Agent or the Print Agent)

Any ideas?

Thank you in advance

1 reply

richardwoods
Do Gooder (Partner)
Forum|alt.badge.img+7
  • Do Gooder (Partner)
  • Dec 4, 2026 1:26 PM UTC

Short answer: Not Mathias, but in case it helps, here is a reworked version. I think three things in the original would stop it, before you even get to the set-up.

What I changed and why

  • MsgBox (Run AppendCODDOC_AtEnd) has no quotes, so VBScript reads it as code, not text. A compile error like that stops the whole macro, which would explain why you never see the message.
  • DOC_NO isn't in the list of attributes IFS passes to macros, as far as I know. The database side ones are named in full, DOCUMENT_NUMBER and DOCUMENT_REVISION, so the original would fail on that line too. That also gives you the revision you were after.
  • LOCAL_FILE_1 is described for the files being checked in, so on a checkout or a new document it may be empty. I've used LOCAL_PATH plus LOCAL_FILE_NAME first and kept LOCAL_FILE_1 as a fallback, with a message if neither file exists.

I also swapped the Selection moves for a Word Range, which doesn't depend on where the cursor is, and added a small helper that reads an attribute with or without .Value, as I'm not completely sure which form your release returns.

Public Sub AppendCODDOC_AtEnd()
Dim fso, filename, folder, tag, wdApp, wdDoc, rng

MsgBox "AppendCODDOC_AtEnd started"

' Local file: path and name come from the database attribute set
folder = GetAttr(ScriptValues, "LOCAL_PATH")
If folder <> "" And Right(folder, 1) <> "\" Then folder = folder & "\"
filename = Replace(folder & GetAttr(ScriptValues, "LOCAL_FILE_NAME"), "/", "\")

' Fallback to the client side value if the above is empty
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(filename) Then
filename = Replace(GetAttr(ClientScriptValues, "LOCAL_FILE_1"), "/", "\")
End If
If Not fso.FileExists(filename) Then
MsgBox "File not found: " & filename
Exit Sub
End If

tag = "CODDOC-" & GetAttr(ScriptValues, "DOCUMENT_NUMBER") & _
"-" & GetAttr(ScriptValues, "DOCUMENT_REVISION")

Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(filename)

' Insert at the very start, then hide it (white, 1pt)
Set rng = wdDoc.Range(0, 0)
rng.InsertBefore tag & vbCr
Set rng = wdDoc.Range(0, Len(tag))
rng.Font.Color = 16777215
rng.Font.Size = 1

wdDoc.Save
End Sub

' Reads an attribute whether Item returns the value or an object with .Value
Function GetAttr(col, name)
Dim v
On Error Resume Next
v = col.Item(name).Value
If Err.Number <> 0 Then
Err.Clear
v = col.Item(name)
End If
If Err.Number <> 0 Then
Err.Clear
v = ""
End If
On Error GoTo 0
GetAttr = CStr(v)
End Function

Set-up to check

  • Main Function on the macro header: AppendCODDOC_AtEnd, with the block connected on the Document Macros page.
  • Process: attaching a new document from a template goes through Edit with no file yet, which is the CREATENEW process, not CHECKOUT. I'd register the macro for CREATENEW as well as Checkout. The Download button uses VIEW and works on a temporary copy, so I wouldn't attach this one there.
  • File type: the macro is tied to WORDM, so the template file itself needs to be that file type. If the template is plain WORD, the macro won't be offered.
  • Aurena Agent: both the Windows app and the browser extension need to be active. A file going straight to Downloads is what I'd expect when the page isn't using the agent at all.
  • Document Class Process Action: RunIfOnlyOne runs it without asking; NoMacro switches it off.

I'd test with only the MsgBox line first, then add the rest. Which command do you use when you try it: Edit on the new document, Check Out, or Download?

Created with the help of Ask Olive.