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)

how to call xrm javascript web resource from html web resource?please help me with this

(0) ShareShare
ReportReport
Posted on by

I have a HTML web page which opens onclick of button on the command bar.HTML page  has got a "create" button,onclick of that button i want to call javascript web resource in the CRM,how this can be achieved?

or onclick of "Create" button on Html web resource a record has to be created in mscrm,i got a javascript web resource to create a record.how to establish connection between html page button and this javascript.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    You add reference of your js web resources to your HTML web resource based on the name that you have given.

    You can refer this post: http://himbap.com/blog/?p=1442

  • Community Member Profile Picture
    on at

    hi,thanks for the reply

    how can i add reference of my script ?will this be ok,

    <script type="text/javascript" src="servername/.../scriptfile&quot;></script>

    i tried doing like this it didn't work

  • Community Member Profile Picture
    on at

    onclick of create button on html resource an account record should be created,if you know any methods please suggest me

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi Sandesh,

    File reference totally depends on the name of your js web resource, if you check my sample code where I have referenced it like following:

    <script type=”text/javascript” src=”SDK.REST.js”></script>

    where my js webresource name is new_/SDK.REST.js

    You can also refer this msdn kb: msdn.microsoft.com/.../gg309473.aspx

    You can use create method of WebAPI to create record. Plese check WebAPI sample codes in my blog that I shared before.

  • Verified answer
    Community Member Profile Picture
    on at

    thanks mahender,i did like this it worked,i included the webAPi code to create record inside the html script tags

    <html>

    <head>

    <script type="text/javascript">

    function createAccount() {

    var serverURL =  window.parent.opener.Xrm.Page.context.getClientUrl();

       var complaint= new Object();

       complaint["new_name"] = document.getElementById("cid").value;

    var req = new XMLHttpRequest();

    req.open("POST",serverURL + "/api/data/v9.0/new_complaints", true);

       req.setRequestHeader("Accept", "application/json");

       req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

       req.setRequestHeader("OData-MaxVersion", "4.0");

       req.setRequestHeader("OData-Version", "4.0");

       req.onreadystatechange = function () {

           if (this.readyState == 4) {

               req.onreadystatechange = null;

               if (this.status == 204||this.status == 200) {

                   var complainttUri = this.getResponseHeader("OData-EntityId");

                   alert("Created complaint with URI: " + complainttUri)

                    } else {

                   var error = JSON.parse(this.response).error;

                   alert(error.message);

               }

           }

       };

       req.send(JSON.stringify(contact));

    }

               </script>

    </head>

    <body>

    Complaint name: <input name="CName" id="cid" type="text">

    <button onclick="createAccount()">   CREATE  </button>

    </body>

    </html>

  • Suggested answer
    Sanjaya Prakash Pradhan Profile Picture
    2,745 User Group Leader on at

    Your solution is here. 

    softchief.com/.../

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