I'm creating dynamic ribbon flyout buttons with ribbon workbench, which to be clicked to trigger actions. Refer the blog:
function DynamicTemplateMenu(commandProperties) {
debugger;
var templates = [; //global templates variable
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ get_templates: 'Yes' })
};
fetch('prod-16.canadaeast.logic.azure.com:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', requestOptions)
.then(response => response.json())
.then(data => {
alert(JSON.stringify(data));
data = data['all-template-data';
for (let i = 0; i < data.length; i ) {
templates.push(data[i);
}
alert(JSON.stringify(templates));
var entityName = Xrm.Page.data.entity.getEntityName();
var isUCI = Xrm.Internal.isUci();
var page = "Form";
var commandId = "mcu.contact.Command.onTemplateClicked";
if (isUCI) {
commandId = entityName "|NoRelationship|" page "|" commandId;
}
var menuXml = '<Menu Id="mcu.contact.Template.Menu">';
menuXml = '<MenuSection Id="mcu.contact.Templates.MenuSection" Sequence="10" DisplayMode="Menu16">'
menuXml = '<Controls Id="mcu.contact.Templates.Control">'
var Name = "";
var Value = "";
if (templates != null) {
for (var i = 0; i < templates.length; i ) {
var Name = templates[i.templateName;
var Value = templates[i.templateId;
menuXml = '<Button Alt="' Name '" Command="' commandId '" Id="' Value '" Sequence="' ((i 1) * 10) '" LabelText="' Name '" TemplateAlias="o1" ToolTipTitle= "' Name '" ToolTipDescription="' Name '" />'
}
menuXml = '</Controls>';
menuXml = '</MenuSection>';
menuXml = '</Menu>';
commandProperties["PopulationXML" = menuXml;
}
});
}
//=========================================================================
function onTemplateClicked(commandProperties) {
alert("template with id " commandProperties.SourceControlId " selected.");
}
//=========================================================================
Run the code, there is a error as below
The Line 78 menuXml format of value as below:
<Menu Id="mcu.contact.Template.Menu">
<MenuSection Id="mcu.contact.Templates.MenuSection" Sequence="10" DisplayMode="Menu16">
<Controls Id="mcu.contact.Templates.Control">
<Button Alt="Temp1111.docx" Command="contact|NoRelationship|Form|mcu.contact.Command.TemplateClicked" Id="MAX0001" Sequence="10" LabelText="Temp1111.docx" TemplateAlias="o1" ToolTipTitle= "Temp1111.docx" ToolTipDescription="Temp1111.docx" />
<Button Alt="Temp2222.docx" Command="contact|NoRelationship|Form|mcu.contact.Command.TemplateClicked" Id="MAX0002" Sequence="20" LabelText="Temp2222.docx" TemplateAlias="o1" ToolTipTitle= "Temp2222.docx" ToolTipDescription="Temp2222.docx" />
<Button Alt="Temp3333.docx" Command="contact|NoRelationship|Form|mcu.contact.Command.TemplateClicked" Id="MAX0003" Sequence="30" LabelText="Temp3333.docx" TemplateAlias="o1" ToolTipTitle= "Temp3333.docx" ToolTipDescription="Temp3333.docx" />
<Button Alt="Temp4444.docx" Command="contact|NoRelationship|Form|mcu.contact.Command.TemplateClicked" Id="MAX0004" Sequence="40" LabelText="Temp4444.docx" TemplateAlias="o1" ToolTipTitle= "Temp4444.docx" ToolTipDescription="Temp4444.docx" />
</Controls>
</MenuSection>
</Menu>
Could you pls help me to check? Thanks.