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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

jscript problem with get_element()

(0) ShareShare
ReportReport
Posted on by
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

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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?

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

  • Community Member Profile Picture
    on at

    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.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans