Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

jscript problem with get_element()

Posted on by Microsoft Employee
Hi,
Following a Google search I found the example code below to convert a text field into a hyperlink (admittedly it is a few years old,  but I can't find anything more recent). When I run this code it fails with the error "ctrl.get_element is not a function". 
My javascript skills are quite basic, so I would appreciate any help you could give to resolve this.
Roy
function ConvertToLink(fldName) {
    if(Xrm.Page.getAttribute(fldName).getValue()!=null)
    {
        var content = Xrm.Page.getAttribute(fldName).getValue();
        var btn = "<a href='javascript: void(0);' onclick=\"window.open(\'" + content + "\', \'windowname1\', \'width=600, height=650\');  return false;\" style='color:blue;text-decoration:underline !important'>" + content +"</a>";
        var ctrl = Xrm.Page.ui.controls.get(fldName)._control;
        // Add the new button
        ctrl.get_element().innerHTML += btn;
        // Hide the textbox
        ctrl.get_element().firstChild.style.display = 'none';
    }
}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: jscript problem with get_element()

    I want to create a link to a local file, rather than a URL as such. I came across this very old article which sort of describes what I am trying to achieve :

    thecrmclub.blogspot.co.uk/.../step-by-step-how-to-open-local-file.html

    It may have worked with CRM 2011 but it doesn't work with Dynamics 16.

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: jscript problem with get_element()

    If you need to add a hyperlink field that does not contain a prefix (http/https), you can create your custom web resource that displays a field like interface, and you can specify whatever rules you want for it.

    If you don't care about http/https, then of course Andrew's answer will provide you with a solution.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: jscript problem with get_element()

    Hello Roy,

    This code is unsupported because it does manipulations with DOM.

    Is't it easier to create new field and set URL type for it?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans