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 :
Customer experience | Sales, Customer Insights,...
Answered

how to send and store data from an external html page to any crm entity

(0) ShareShare
ReportReport
Posted on by 202

Hello Everyone ,

this is an urgent query please help with steps by steps.

i have created one html page where i have given some lebel and text box example- Topic , First name, Last name , Email and one submit button .

this web resource i have added in ms crm app like tthis .

pastedimage1599030162225v2.png

when i click this HTML then this page get open in new window.

pastedimage1599029966313v1.png

here is the code for this creating html page

<html>
<head>
<meta><meta><meta><meta><meta><meta><meta></head><body onfocusout="parent.setEmailRange();" style='overflow-wrap: break-word;'>


<form id="myForm" action="/action_page.php">
<label for="topic">Topic:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
<input type="text" id="topic" name="topic"><br><br>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<label for="email">Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
<input pattern=".+@biztech.com" size="30" required=""><br>
<p>Please Enter in following format only:- @biztech.com</p>


<!--<input type="email" id="email" name="email"><br><br> this Line is commented -->
<input type="checkbox" id="Admin" name="Admin" value="Yes">
<label for="Admin"> Acknowledge Admin</label><br><br>
<input type="submit" onclick="saveShanges()" value="Submit">
</form>

</body></html>

my requirement is -- when i fill all above info in html page those data get save in CRM table (Example - Lead). and create one record for it in lead with above information in 

lead entity . 

please let me know how can i achieve this soon urgent.

regrads

Amit 

amitsharma.mscrm@gmail.com

I have the same question (0)
  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Amit,

    You can use CRM REST Builder to automatically generate the code to create new lead.

    https://github.com/jlattimer/CRMRESTBuilder

    After importing the solution, a icon will appear Settings > Customizations

    pastedimage1599035702518v1.png

    pastedimage1599035745869v2.png

    pastedimage1599035762462v3.png

    Then put the code into your saveChanges function.

    Regards,

    Clofly

  • amity Profile Picture
    202 on at

    this is what i did bro but some error is coming ......................

    please help me with this

    <html>

    <head>

    <form id="myForm" action="/action_page.php">

     <label for="topic">Topic:       </label>

     <input type="text" id="topic" name="topic"><br><br>

     <label for="fname">First name:</label>

     <input type="text" id="fname" name="fname"><br><br>

     <label for="lname">Last name:</label>

     <input type="text" id="lname" name="lname"><br><br>

     <label for="email">Email:       </label>

     <input pattern=".+@biztech.com" size="30" required=""><br>

     <p>Please Enter in following format only:- @biztech.com</p>

     <!--<input type="email" id="email" name="email"><br><br>   this Line is commented  -->

     <input type="checkbox" id="Admin" name="Admin" value="Yes">

     <label for="Admin"> Acknowledge Admin</label><br><br>

     <input type="submit" onclick="saveShanges()" value="Submit">

    </form>

    <script>

    function saveShanges() {

    var entity = {};

    entity.subject = "Hello";

    entity.firstname = "amit";

    entity.lastname = "sharma";

    entity.emailaddress1 = "amit@biztech.com";

    Xrm.WebApi.online.createRecord("lead", entity).then(

       function success(result) {

           var newEntityId = result.id;

       },

       function(error) {

           Xrm.Utility.alertDialog(error.message);

       }

    );

    Xrm.Page.data.entity.save();

    alert("The form was submitted");

    }

    </script>

    </body></html>

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Hi Amit,

    You have two options I can think of:

    1. Within your webresrouce - using web api created a lead record in dynamics. You can use the tool suggested as above.   docs.microsoft.com/.../create-entity-web-api  

    2. you can simply call an action by passing all these values and register a plugin on that to created a lead from your code.

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Please debug the script and see what error are you getting. Also since its a stand alone web resource, the way you will get these fieldname and records is slightly different : community.dynamics.com/.../use-xrm-webapi-in-a-stand-alone-web-resource

  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Amit,

    We should replace Xrm with parent.Xrm to make the web resource can access to its parent Xrm object.

    (Xrm exists in form, and we could regard form as parent of web resource.)

    Regards,

    Clofly

  • amity Profile Picture
    202 on at

    i am trying the same with this but still getting error ..

    if you can suggest me , if there lines any wrong here

    <html>

    <head>

    <form id="myForm" action="/action_page.php">

     <label for="topic">Topic:       </label>

     <input type="text" id="topic" name="subject"><br><br>

     <label for="fname">First name:</label>

     <input type="text" id="fname" name="firstname"><br><br>

     <label for="lname">Last name:</label>

     <input type="text" id="lname" name="lastname"><br><br>

     <label for="email">Email:       </label>

     <!--<input pattern=".+@biztech.com" size="30" required=""><br> -->

     <input type="email" id="email" name="emailaddress1"><br><br>

     <p>Please Enter in following format only:- @biztech.com</p>

     <input type="checkbox" id="Admin" name="Admin" value="Yes">

     <label for="Admin"> Acknowledge Admin</label><br><br>

     <input type="submit" onclick="saveShanges()" value="Submit">

    </form>

    <script>

    function saveShanges() {

    //var Xrm = parent.Xrm;

    var entity = {};

    entity.subject = "Hello";

    entity.firstname = "amit";

    entity.lastname = "sharma";

    entity.emailaddress1 = "amit@biztech.com";

    parent.Xrm.WebApi.online.createRecord("lead", entity).then(

       function success(result) {

           var newEntityId = result.id;

       },

       function(error) {

           parent.Xrm.Utility.alertDialog(error.message);

       }

    );

    parent.Xrm.Page.data.entity.save();

    alert("The form was submitted");

    }

    </script>

    </body></html>

  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Amit,

    Please apply following changes to your original code.

    1. Remove action="/action_page.php" attribute of the form element

    If we keep it, it means that we send form data to a service endpoint called "/action_page.php", however, such URL not exists, and we just use API(Xrm.WebApi.online.createRecord) of Dynamics.

    2. Change type of the submit button to "button" instead of "submit", "submit" type button is only required when the action attribute of form has a value.

    Below is my modified code:

    
    
    
    
        
    
            
    
            







    Please Enter in following format only:- @biztech.com



    Now it works well. 

    3630.JPG

    pastedimage1599097739959v1.png

    Regards,

    Clofly

  • amity Profile Picture
    202 on at

    Hello Clofly ,

    thanks for your response ,

    your code is working fine , you are adding this web resource to within the form of lead in new tab but i have added this web resource to out side of the form like this.

    pastedimage1599109295102v1.png

    when i click this it will open in new tab like this 

    pastedimage1599109381505v2.png

    this is not working , when i entered all above and click submit then no response .

    and also when i go with ur given (lead form itself) test- tab and then entered in boxes and click submit then its not saving the value of  entered in text box. its only 

    saving the data given in function

    pastedimage1599109980109v3.png

    in this data only getting save not the entered new one in text boxes.  

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Amit,

    If you want to make web resource work in new tab of browser, (xxx.crm.dynamics.com/{637347091960021936}/webresources/new_LeadForm)

    then we should use pure Web API directly, because Xrm is only available in Dynamics form.

    The Web API format code can be also generated by CRM Rest Builder.

    Secondly, in your original code, firstname and lastname and other form data are fixed value, we need to use document.getElementById to get value of input text boxes.

    I added some validation: firstname, lastname and email are all required when clicking submit button.

    x11.JPG

    Successes submission and new record:

    x2.JPG

    pastedimage1599114600555v1.png

    Full code:

    
    
    
    
    
    
        








    Please Enter in following format only:- @biztech.com



    It works in both new tab and site map area.

    Regards,

    Clofly

  • amity Profile Picture
    202 on at

    thanks so much my dear brother .it worked smoothly .

    thanks for your valuable time .

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans