Template #PROMPT with FIELD doesn't show all fields

I have a template that requries a BrowseBox(ABC).
I wanted to limit the available selections to the primary file, so I used this approach.
#PROMPT(‘Field2’,FIELD(%Primary)),%CpField

However, this does not list the fields inside the DateTime structures, and these are the fields I needed here.
I have workaround without scope, but ideally I would like to limit available fields to those that are both in the primary file and visible in the listbox

Should I build a list from %ControlField?

In this type of tricky situation, I tend to create a local multi-valued symbol within a #PREPARE section above the #PROMPTs. Then I can make my #PROMPT,FROM(%ThatSymbol). Within the #PREPARE section, you can apply any logic necessary for your situation.

2 Likes

It has been a while since I needed to write new templates, so I am rusty.
It seems the variables from the parent template is not available during #PREPARE?
I looked in my old templates and they usually can access %ListControl.
But I get "Unknown variable ‘%ListControl’.
This is my attempt

#EXTENSION(TEMP,'TEMP'),Procedure,Req(BrowseBox(ABC)),MULTI
#PREPARE
#Declare(%MySymbol),MULTI
#Fix(%Control,%ListControl)
#For(%ControlField)
   #ADD(%MySymbol,%ControlField)
#EndFor
#EndPrepare
#PROMPT('Field in list',From(%MySymbol)),%MyField

This might be similar code? If so, you can do it on your tabs for the template, you probably need to use…

#FIND(%ControlInstance,%ActiveTemplateParentInstance,%Control)

#GROUP(%GWBTab2)   #! How to sort
#!-----------------------------------------------
  #TAB('2 How to sort')
    #PREPARE
      #DECLARE(%GWBBrowseColumns),MULTI
      #DECLARE(%GWBBrowseColumnCount)
      #FIND(%ControlInstance,%ActiveTemplateParentInstance,%Control)
      #PURGE(%GWBBrowseColumns)
      #DECLARE(%GWBLocalVariableColumnsInlist)
      #SET(%GWBLocalVariableColumnsInlist,'0,0')   #! Ensure there are always at leat two values for inlist to search
      #FOR(%ControlField)
        #ADD(%GWBBrowseColumns,%ControlField)
        #SET(%GWBBrowseColumnCount, %GWBBrowseColumnCount + 1)
        #FIND(%Field,%GWBBrowseColumns)
        #IF(%Field = '')
          #SET(%GWBLocalVariableColumnsInlist,%GWBLocalVariableColumnsInlist & ',' & %GWBBrowseColumnCount) 
        #ENDIF
      #ENDFOR
    #ENDPREPARE

    ...rest of tab

1 Like

Correct! In #PREPARE you are within the context of entering the #PROMPTs. The %ListControl value isn’t set until code generation time. However, you should still be able to get to that control. First of all, look to see how %ListControl itself is set:

#SET(%ListControl,%GetControlName())

Here’s that called group in ABWindow.tpw:

#GROUP(%GetControlName,%SearchReport=%False),PRESERVE      #!Gets the control name for the current active template
#IF(%Searchreport)
  #FIND(%ReportControlInstance,%ActiveTemplateInstance,%ReportControl)
  #RETURN (%ReportControl)
#ELSE
  #FIND(%ControlInstance,%ActiveTemplateInstance,%Control)
  #RETURN (%Control)
#END

The line you care about is this:

  #FIND(%ControlInstance,%ActiveTemplateInstance,%Control)

You should be able to do something similar with %ActiveTemplateParentInstance:

#GROUP(%GetParentControlName)
  #FIND(%ControlInstance,%ActiveTemplateParentInstance,%Control)
  #RETURN (%Control)
2 Likes