web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Create a button in CRM 2016 using Javascript

(0) ShareShare
ReportReport
Posted on by 262

Hi,

I have a wen resource whisch is written in javascript.

This web resource rates a button and my system is crm 2016.

The code for the button is supported ÅŸin CRM 2015;but in CRM 2016 not.

The button code is:

var latLon = getField("new_enlemboylam");
if (latLon && latLon.getValue() != null) {
var insertAfterField = document.getElementById('new_enlemboylam_d');
parent.document.document.getElementById('new_enlemboylam_d').insertBefore(createButton("btnMap", "Google Map", 100, function () {
var s = "http://" + window.location.host + "/ISV/vizyonera/map/bayimap.html?geo=" + latLon.getValue();
window.open(s, "", "dialogWidth:800px; dialogHeight:600px; center:yes");
}), parent.document.document.getElementById('new_enlemboylam_d').nextSibling);

I use code validation tool. The tool shows the .nextSibling word in blue. How can i fix it . I use this code while the form is loading. On loading it gives me javascript error. When ı remove the web resource form Onload event, the form works correctly and the form dos not give me error. But ı need the button .

Can anyone help me please?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Alagunellaikumar Profile Picture
    6,212 on at

    Hi

    Custom validation tool not check html source code. You have to debug it like

    parent.document.document.getElementById('new_enlemboylam_d') has null or not if not null then check what is next sibling value

    Please refer below URL

    community.dynamics.com/.../185309

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    Try the code below.

    function createButton() {
    var atrname = 'foobar';
    if (window.parent.document.getElementById(atrname) != null) {
        var fieldId = 'field' + atrname;
        var elementId = window.parent.document.getElementById(atrname + '_d');
        var div = window.parent.document.createElement('div');
        div.style.width = '20%';
        div.style.textAlign = 'right';
        div.style.display = 'inline';
    
        var childDiv = elementId.getElementsByTagName('div')[0];
        childDiv.style.display = 'none';
    
        elementId.appendChild(div, elementId);
        div.innerHTML = '<button id="' + fieldId + '"  type="button" style="margin-left: 4px; width: 50%;" >CRM Save Button</button>';
        window.parent.document.getElementById(atrname).style.width = '80%';
        window.parent.document.getElementById(fieldId).onclick = function () { OnClickFunction(); };
    
        }
    }

    See the discussion below.

    http://stackoverflow.com/questions/39410212/create-button-in-crm-2016-form-without-a-field-using-javascript

  • Suggested answer
    tw0sh3ds Profile Picture
    5,600 on at

    Hi,

    This code is not supported neither in CRM 2015 nor in CRM 2016 (if something is working it does not automatically mean that it's supported...). The only way to show a button on a form is to create a web resource, put in on the form and show button on that web resource. You are now modifying CRM DOM, which is totally unsupported.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans