RE: CRMScript: DocTmplHeadingLink Query
HI James,
OK, to address your OP "how to determine if a particular Template is visible under a particular Heading?"
I created a method that will loop over all the headings and determine if the templateId has that heading selected.
Bool IsSelectedUnderHeading(String listName, String heading, Integer templateId) {
NSListAgent listAgent;
NSSelectableMDOListItem[] headings = listAgent.GetHeadingsForListItemFromListName(listName, templateId, false);
//printLine("Headings count: " + headings.length().toString());
for(Integer i = 0; i < headings.length(); i++)
{
//printLine("Headings name: " + headings[i].GetName());
if((headings[i].GetName() == heading) && headings[i].GetSelected())
{
return true;
}
}
return false;
}
Then you could use is like this:
printLine("IsSelected = " + IsSelectedUnderHeading("DocTmpl", "System", 155).toString());
Alternatively, maybe you want to get a list of all Headings, and see what templates are associated with each. In that case, here is a simple struct to contain the Heading name and all child templates (as NSMDOListItem[]).
An afterthought...Maybe a Map would have been better suited... But having a Struct gives it abillity to grow...
struct Heading
{
String Name;
NSMDOListItem[] ChildItems;
};
// constructor
Heading Heading(String name, NSMDOListItem[] children)
{
Heading heading;
heading.Name = name;
heading.ChildItems = children;
return heading;
}
Then create a method to get all document templates and transform them into a heading array:
Heading[] GetAllHeadingsAndChildren()
{
Heading[] headings;
NSMDOAgent mdo;
NSMDOListItem[] documentTemplates = mdo.GetList("doctmpl", false, "", false);
for(Integer i = 0; i < documentTemplates.length(); i++)
{
NSMDOListItem[] childItems = documentTemplates[i].GetChildItems();
if(childItems.length() > 0)
{
Heading h = Heading(documentTemplates[i].GetName(), childItems);
headings.pushBack(h);
}
}
return headings;
}
Then all you have to do is call it and print out all the Heading's to see them formatted accordingly.
Heading[] heads = GetAllHeadingsAndChildren();
for(Integer i = 0; i < heads.length(); i++)
{
printLine("----------------------------");
printLine("Head name: " + heads[i].Name);
printLine("----------------------------");
//NSMDOListItem[] childItems = heads[i].ChildItems;
for(Integer j = 0; j < heads[i].ChildItems.length(); j++)
{
printLine("Template name: " + heads[i].ChildItems[j].GetName());
}
}
Should get something like this:

Hope this helps!