web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    RE: Create a button in CRM 2016 using Javascript

    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
    RE: Create a button in CRM 2016 using Javascript

    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
    RE: Create a button in CRM 2016 using Javascript

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans