trigger PreviewDocument(DocId: Text) begin Message('Trigger PreviewDocument Invoked'); end;
event PreviewDocument(DocId: Text);
'<div id=buttonPreview>' + '<button onclick="previewDocumentFunction(["' + Docid + '"])">Preview</button>' +
function previewDocumentFunction(DocId) { Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('PreviewDocument', [DocId]); }
document.querySelector('buttonPreview').addEventListener('click', previewDocumentFunction);
<button onclick="previewDocumentFunction(["' + Docid + '"])">Preview</button>' +
["' + Docid + '"]
previewDocumentFunction(DocId)
Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('PreviewDocument', [["' + Docid + '"]]);
DocId = 'XYZ'; button.onclick = function () { Microsoft.Dynamics.NAV.InvokeExtensibilityMethod("ButtonClicked", [DocId]); };
document.addEventListener("DOMContentLoaded", function () { var container = document.getElementById("controlAddIn"); if (container) { var button = document.createElement("button"); button.innerText = "Click Me"; button.style.padding = "10px"; button.style.fontSize = "16px"; button.style.cursor = "pointer"; DocId = 'XYZ'; button.onclick = function () { Microsoft.Dynamics.NAV.InvokeExtensibilityMethod("ButtonClicked", [DocId]); }; container.appendChild(button); } });
Answers
I see two potential problems with your code - but I am not sure, because your sample code is too small.
First of all, I think there might be too many and incorrectly placed quotation marks, that might lead to syntax errors for example, here:
looks like the first mark inside the array is closing the mark that is right after onclick.
Second of all
I think you are passing an array
into the function
which is putting this into another array, resulting in passing an array of arrays into the Event, and eventually it ends up with something like this:
which cannot be interpreted correctly by AL; thus nothing happens.
I have made a sample button like this:
and it works perfectly fine.
Here is my full javascript code:
I did this and it worked.
Thank you for your time. Have a great week