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 365 | Integration, Dataverse...
Answered

Get field value when tying value in with Javascript

(0) ShareShare
ReportReport
Posted on by 2,139

Hi guys!

I need to get the actual value of a field at the moment of typing any value on it. I need a function that should be fire at the moment when the value is changed. I don't mean get the value when the form is saved. I need to get the value of the field "online".

There is any way to do that?

Update:

I have added the following code to my onLoad event

// A namespace defined for the sample code
// As a best practice, you should always define 
// a unique namespace for your libraries
var Sdk = window.Sdk || {};
(function ()
{
    // Code to run in the form OnLoad event
    this.formOnLoad = function (executionContext)
    {        
        var formContext = executionContext.getFormContext();
        var name = formContext.getAttribute("name").getValue();
        var d = window.parent.document.getElementById("name");
        d.oninput = function () { suggest("party", name   d.oninput.arguments[0].data); };

    }

    function suggest(resource, query)
        {
            var API_KEY = "test";
            var xhr = new XMLHttpRequest();
            var serviceUrl = "Url"   resource;
            xhr.open("POST", serviceUrl, true);
            xhr.setRequestHeader("Authorization", "Token "   API_KEY);
            xhr.setRequestHeader("Content-Type", "application/json");
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    var json = JSON.parse(xhr.responseText);
                    console.log(json);
                }
            };
            var data = "{ \"query\": \""   query   "\" }";
            xhr.send(data);
        }
}).call(Sdk);

I now that this code is unsopported but i can't find a correct solution. With my code i can't get the value of the last input keyword but i cant get the text value that i already typed. Any idea?

I'm using CRM 365 v.9 On premise

I have the same question (0)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Are you talking about onkeypress event ? You can do with Field onchange event.Register a Js function in field onchange event and get the value. 

    docs.microsoft.com/.../attribute-onchange

  • betlejuice Profile Picture
    2,139 on at

    Yes, i'm talking about onkeypress event. As I understand I need to add a code on my OnLoad event, for example

    var Sdk = window.Sdk || {};
    (function ()
    {    // Code to run in the form OnLoad event
        this.formOnLoad = function (executionContext)
        {
            var formContext = executionContext.getFormContext();
            formContext.getAttribute("my_fieldname").addOnChange(myFunction);
        }
        
        function myFunction()
        {
          //todo
        }
    }).call(Sdk);

    Am I correct?

  • gdas Profile Picture
    50,091 Moderator on at

    Yes this is also work for you , you can also add directly function in the field properties  by going to form editor.

  • betlejuice Profile Picture
    2,139 on at

    I have added directly the function to my field. The function fires when the focus on the field is changed. I need to get the value anytime when I press a keyword.

    function myfunc(executionContext){
            var formContext = executionContext.getFormContext();
            formContext.getAttribute("name").addOnChange(suggest);
    }
    
    function suggest(){
      alert("HI");
    }

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 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans