Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to access the webresource cotrols from another html webresource on CRM 2016 Form.

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi Expert,

I have two html webresources in my customer form, one contains a multitab and second contains some tiles, designed using bootstrap and JQuery for events. Want to initiate a Click event of tab exist on first webresource on the click of tiles exist on second webresource.

I have prepared the script on simple html page first all code is working there but not on crm form.

1. How can I access the tab controls using JQuery from first webresource. ?

2.  I have written some scripts on each html webresources,  can I use the same script/function from another html webresource. ?

Webresource_1 

//html

<div class="row">     
     <ul id="tab_container_01" class="nav nav-tabs">
     <li id="tab_cases"><a id="ahref_cases" href="#">Cases</a></li>
     </ul>
</div>
//script
//Following script is working fine on the same page
<script type="text/javascript">
$("ul.nav-tabs").on("click", "li", function () {
    var selectedTabText = ($(this).find("a").text());
    var tabs = window.parent.Xrm.Page.ui.tabs;
    //Some toggle script
});

</script>



Webresource_2
//html

<div class="panel">           
    <div> Open Cases </div>
</div>

//script
<script type="text/javascript">
$(".panel").on("click", "div", function () {

// following not working on crm form
$("#tab_cases").addClass('active');
$("#tab_cases").parent().siblings().removeClass('active'); //length 0, id not detecting

//window.parent.$("#tab_cases").parent().siblings().removeClass('active');

/* trigger click event on the li */
//trying to use function written on webresource_1 script

$("#tab_cases").closest("ul.nav-tabs li").trigger('click'); //*Not Triggering*
});
</script>

*This post is locked for comments

  • Suggested answer
    Alagunellaikumar Profile Picture
    Alagunellaikumar 6,210 on at
    RE: How to access the webresource cotrols from another html webresource on CRM 2016 Form.

    Hi

    Accessing HTML

    parent.Xrm.Page.getControl("WebResourceName").getObject().contentWindow

    Example:

    parent.Xrm.Page.getControl("WebResourceName").getObject().contentWindow.window.MethodName();

  • ScottDurow Profile Picture
    ScottDurow 19 on at
    RE: How to access the webresource cotrols from another html webresource on CRM 2016 Form.

    Hi,

    In addition to Nithya's suggestion, I would recommend encapsulating what you need to do in a function on the second webresource, so instead of accessing the DOM directly from Webresource you would simply call a function:

    parent.Xrm.Page.getControl("WebResource_<Name>").getObject().contentWindow.window.fooBar(someParameter);

    See www.develop1.net/.../Calling-a-function-in-a-Html-Webresource-from-another-Javascript-Webresource.aspx

    Hope this helps!

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: How to access the webresource cotrols from another html webresource on CRM 2016 Form.

    Hi,

    You could try the following code using JavaScript. 

    parent.Xrm.Page.getControl("WebResource_1").getObject().contentWindow.document.getElementsById('ul.nav-tabs');

    Hope this helps you to solve your issue.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans