Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Query database from Web resource

Posted on by 12,070 Super User 2024 Season 1

Hi all 

I create a Web resource as shown below

3247.Enum-Values-for-voucher-entity.png 0676.Untitled1.png

I add a button and open this Web page through the button. I add a button using ribbon workbench.

2642.Untitled2.png  1104.Untitled3.png

When I click to this button. It opens this form to me as shown below

7532.Untitled4.png

I need this text box value to update my form's method field . What can I do to fulfill my requirement?

My Form's method field is shown below

0508.Untitled5.png

Thank you

*This post is locked for comments

  • Verified answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Query database from Web resource

    Hi all,

    I find my answer own.

    <html>

       <head>

            <title> </title>

     <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>

     <script src="aw_SDK.REST.js" type="text/javascript"></script>

     <script src="aw_json2.js" type="text/javascript"></script>

     <script type="text/javascript">

                   function myFunction() {

    debugger;

    var x = document.getElementById("myText").value;

    if(x == "VPA" ||x == "vpa" ){

    var currentleadId = window.parent.opener.Xrm.Page.data.entity.getId();

    var opportunity = {};

    var lookup = new Array();

    var changes = {

    aw_PaymentMethod: {        

    Id: "83D67CFE-09A1-E611-B7CD-005056C00008", // Guid of the parent account

    LogicalName: "aw_paymentmethod"

    }

    }

    SDK.REST.updateRecord(

    currentleadId,

    changes,

    "Opportunity",

    function () {

    //writeMessage("The account record changes were saved");

    },

    errorHandler

    );

    }

    }

    function errorHandler(error) {

    alert(error.message);

    }

                 </script>

    <meta charset="utf-8">

    <body >  

     <form method="post" action="">

      <fieldset>

          <legend>Input Payment Method</legend>

          <p>

            <label>Payment Method</label>

            <input id="myText" type="text">

          </p>

        </fieldset>

     <button type="button" onclick="myFunction()">OK</button>

      </form>

    </body>  

    </html>

    Thank you

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Query database from Web resource

    Hi all

    I write the following code on me web resource but it does not give any effect to my opportunity form. It is not updating aw_paymentmethod value on the form. Before and running this script form has no change. Please suggest me Where I am wrong.?

    <html>

       <head>

            <title> </title>

                 <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>

                 <script type="text/javascript">

                   function myFunction() {

    debugger;

    var x = document.getElementById("myText").value;

    if(x == "VPA" ||x == "vpa" ){

      var lookup = new Array();

      lookup[0] = new Object();

      lookup[0].name = "VPA";

      lookup[0].id = "83D67CFE-09A1-E611-B7CD-005056C00008";

      lookup[0].entityType ="aw_paymentmethod";

      window.parent.opener.Xrm.Page.getAttribute("aw_paymentmethod").setValue(lookup);

    }

    }

                 </script>

    <meta charset="utf-8">

    <body >  

     <form method="post" action="">

      <fieldset>

          <legend>Input Payment Method</legend>

          <p>

            <label>Payment Method</label>

            <input id="myText" type="text">

          </p>

        </fieldset>

     <button type="button" onclick="myFunction()">OK</button>

      </form>

    </body>  

    </html>

  • Verified answer
    Alagunellaikumar Profile Picture
    Alagunellaikumar 6,210 on at
    RE: Query database from Web resource

    Hi

    Use the below code

    In that ticker symbol, use your opportunity field

    <html>

        <head>

             <title> </title>

                  <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>

                  <script type="text/javascript">

                    function myFunction() {

    debugger;

      var x = document.getElementById("myText").value;

      window.parent.opener.Xrm.Page.getAttribute("tickersymbol").setValue(x);

    }

          </script>

    <meta charset="utf-8">

     <body >  

      <form method="post" action="">

       <fieldset>

           <legend>Input Payment Method</legend>

           <p>

             <label>Payment Method</label>

             <input id="myText" type="text">

           </p>

         </fieldset>

      <button type="button" onclick="myFunction()">OK</button>

       </form>

     </body>  

    </html>

  • Aileen Gusni Profile Picture
    Aileen Gusni 44,522 on at
    RE: Query database from Web resource

    For this case:

    "As you know when we close opportunity as won, save button is disabled. I need to work on this OK button."

    Yup, you need to trigger onsave programmatically.

    Or you can do: Update from odata then refresh the form.

    Thanks.

  • Aileen Gusni Profile Picture
    Aileen Gusni 44,522 on at
    RE: Query database from Web resource

    Hi Abdul,

    Mentioned before, you can refer that link to get the current attribute value.

    Thank you.

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Query database from Web resource

    Hi Aileen Gusni

    How can I get current record from the form and pass it to this web resource and then get the value from this web resource and query to the database?

    Thank you

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Query database from Web resource

    Hi Aileen Gusni

    As you know when we close opportunity as won, save button is disabled. I need to work on this OK button.

    Thank you

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Query database from Web resource

    Hi Aileen Gusni

    What do you mean by "If the field is the same entity form where by you put your web resource" ?

    I write following HTML to make my form

    <!DOCTYPE html><html lang="en"><head>

       <title>formDemo.html</title>

    <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>

                  <script type="text/javascript">

                      function ABC() {

                          debugger;

                          var form = document.forms[0];

                          var context = GetGlobalContext();

                          var attrVal = window.parent.document.crmForm.<Attribute Name>.value;    

                          // Your code for your functionality                                                                                            }

    </script>

       <meta charset="UTF-8">

     </head>

     <body>

       <form>

         <fieldset>

           <legend>Input Payment Method</legend>

           <p>

             <label>Payment Method</label>

             <input id="myText" type="text">

           </p>

         </fieldset>

     <button type="button">OK</button>

       </form>

    </body></html>

    which is look like as shown

    Untitled9.png

    When I click on Ok button it will update my method field on form which is on opportunity. This my desired. Please help me.

    Thank you

  • Aileen Gusni Profile Picture
    Aileen Gusni 44,522 on at
    RE: Query database from Web resource

    Hi Abdul,

    If the field is the same entity form where by you put your web resource

    You can refer here:

    crmjavascripts.blogspot.com/.../how-to-get-crm-entity-attribute-value.html

    To Update, you can use also the same method, but using set value, instead of getvalue()

    It is same as the standard JS but you just need this one:

    var Xrm = window.parent.Xrm;

    To let the code in web resource understand who Xrm is.

    community.dynamics.com/.../howto-html-js-webresources

    But it needs to trigger onsave js to update or ask the user to hit onsave to commit it manually based on user request.

    Or..you can use odata to update or you can use custom action.

    Hope this helps.

    Thanks

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Query database from Web resource

    Hi Clement

    When I close my entity as won at that time I need this all. How can I get this text box value and query it to database to update my value.

    Thank you

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans