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)

Javascript cross code communication with Web Resources on Forms

(0) ShareShare
ReportReport
Posted on by 2,601

I have a web resource which is html/javascript and contains a button along with it's action code.

I have 2 questions

1. The code in the web resource can't access any xrm objects on the main form. For example I want to get a field value using the xrm getvalue().  
I've tried both these but they both come back with the error '{fieldname} is undefined'

a. Xrm.Page.getAttribute({fieldname}).getValue();
b. parent.Xrm.Page.getAttribute({fieldname}).getValue();

2. In the web resource is it possible for the onclick action to call a javascript action which is in a javascript resource on the main form?

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Hosk Profile Picture
    on at

    I think maybe the CRM SDK may help you.  I don't think it passes the context out to an HTML page by default

    msdn.microsoft.com/.../gg309536.aspx

    msdn.microsoft.com/.../jj602948.aspx

    msdn.microsoft.com/.../gg309473.aspx

  • Verified answer
    jlattimer Profile Picture
    24,562 on at

    Try window.parent.Xrm...

    Also review this post on referencing the ClientGlobalContext in a web resource: 

    http://dynamicscrm2011.wordpress.com/2011/05/31/crm-2011-web-resource-part-2-how-to-use-clientglobalcontext-js-aspx/

  • CU21020959-0 Profile Picture
    2,601 on at

    Thanks for your replies.

    Regarding Question 1 I had made a typo and left out the double quotes around the field name, the code below works.

    parent.Xrm.Page.getAttribute("{fieldname}").getValue();

    I'm still not sure about Question 2

  • Verified answer
    Vijay Waghmare Profile Picture
    on at

    I assume you are referencing to some function defined in JS web resource and registered on main entity form. If so, you can access function through HTML web resource as

    window.parent.functioname();

    Thanks,

    Vijay Waghmare

  • CU21020959-0 Profile Picture
    2,601 on at

    Thanks Vijay - exactly what I was looking for.

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