Control addin event arguments
 
            
                
                    josalm                
                
                    Member Posts: 7                
            
                        
            Hi,
According documentation the arguments in events within control addin must belong to an array.
I can't understand how should this work with arguments. Here's my code:
AL:
trigger PreviewDocument(DocId: Text)
begin
    Message('Trigger PreviewDocument Invoked');
end;
AL Control Addin:
event PreviewDocument(DocId: Text);
Js
script: (this is where the button is added inside a loop) In here, i
tried without the brackets, with them and with and without question
marks.
'<div id=buttonPreview>' + '<button onclick="previewDocumentFunction(["' + Docid + '"])">Preview</button>' +
function previewDocumentFunction(DocId) {
    Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('PreviewDocument', [DocId]);
}
document.querySelector('buttonPreview').addEventListener('click', previewDocumentFunction);
After inspect the page:

Nothing happens after the click.
Any ideas?
0                
            Best Answer
- 
            Hey,
 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:<button onclick="previewDocumentFunction(["' + Docid + '"])">Preview</button>' + 
 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["' + Docid + '"] 
 into the functionpreviewDocumentFunction(DocId) 
 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:Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('PreviewDocument', [["' + Docid + '"]]);
 which cannot be interpreted correctly by AL; thus nothing happens.
 I have made a sample button like this:DocId = 'XYZ'; button.onclick = function () { Microsoft.Dynamics.NAV.InvokeExtensibilityMethod("ButtonClicked", [DocId]); };
 and it works perfectly fine.
 Here is my full javascript code: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); } });0
Answers
- 
            Hey,
 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:<button onclick="previewDocumentFunction(["' + Docid + '"])">Preview</button>' + 
 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["' + Docid + '"] 
 into the functionpreviewDocumentFunction(DocId) 
 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:Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('PreviewDocument', [["' + Docid + '"]]);
 which cannot be interpreted correctly by AL; thus nothing happens.
 I have made a sample button like this:DocId = 'XYZ'; button.onclick = function () { Microsoft.Dynamics.NAV.InvokeExtensibilityMethod("ButtonClicked", [DocId]); };
 and it works perfectly fine.
 Here is my full javascript code: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); } });0
- 
            
 Thanks, for the insight. I didn't understood the syntax at first since it's my first time using JS.Hey,
 I did this and it worked.'<div id=buttonPreview>' + '<button onclick="previewDocumentFunction(' + '\'' + Docid + '\'' + ')">Preview</button>' + '</div>'
 Thank you for your time. Have a great week1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
