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)

Xrm.Page.getAttribute("") is not a function at pdf.html

(0) ShareShare
ReportReport
Posted on by

Hi All ,

I'm trying to export to pdf with pdfjs library a value field of a custom entity, But i was getting error "Xrm.Page.getAttribute(...) is not a function at pdf.html. Somenone can help me?

This is my code:

<!DOCTYPE html>
<html>
<head>
    <script src="cdnjs.cloudflare.com/.../jspdf.min.js" integrity="sha384-B3ZwMLt/CqFLkq5omwYXeXs+qquHvXKcwP56Ue+09Fet7TmYmwk/35GWwejM5vWg" crossorigin="anonymous"></script>
    <script src="cdn.static.runoob.com/.../jquery.min.js"></script>
    <script src="cdnjs.cloudflare.com/.../jspdf.debug.js" integrity="sha384-THVO/sM0mFD9h7dfSndI6TS0PgAGavwKvB5hAxRRvc0o9cPLohB0wb/PTA7LdUHs" crossorigin="anonymous"></script>
    <script type="text/javascript" src="../ClientGlobalContext.js.aspx"></script>
</head>
<body>
    <div>
        <button id="savepdf">
            savepdf
        </button>

    </div>
    <script>
        const doc = new jsPDF();
        let button = document.querySelector('button');
        button.addEventListener('click', printPdf)
        
        function printPdf()
        {
            var reasons = Xrm.Page.getAttribute("cdm_managereasons").getValue();
            doc.text(10,10,'${reasons}$');
            
            doc.save();
        }
    </script>
</body>
</html>

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    Try with this  -

    var reasons = window.parent.Xrm.Page.getAttribute("cdm_managereasons").getValue();

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at

    Hi Ghalandor90,

    Actually you are trying to use Xrm library outside of CRM and hence you are getting this error.

    Please do use following code in case of you need to retrieve field value inside HTML page.

    1. Internal HTML web resource (On CRM form only):

    var reasons = parent.Xrm.Page.getAttribute("cdm_managereasons").getValue();

    2. External HTML web resource (HTML window popup):

    var reasons = window.parent.Xrm.Page.getAttribute("cdm_managereasons").getValue();

  • Community Member Profile Picture
    on at

    Hi Pravin, thanks  for your reply, but I tried with window.parent.Xrm.Page.getAttribute("cdm_managereasons").getValue(); but I have the same error.

    window.parent.Xrm.Page.getAttribute is a not function...

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at

    Hey ,

    Can you please debug once with window.parent.Xrm only

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