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

check current record active javascript

(0) ShareShare
ReportReport
Posted on by 55

I need to check if my current record is active through JS:,but im always getting a null result .

 checkincident: function () { 
try {
	
var incidentid = Xrm.Page.data.entity.getId();


var query = "/IncidentSet?$select=name,statecode&$filter=IncidentId eq guid'"   incidentid   "'";

 var serverUrl = Xrm.Page.context.getClientUrl();
 var ODataURL = serverUrl   "/XRMServices/2011/OrganizationData.svc"   query;
 var results = null;
 
 $.ajax({
 type: "GET",
 contentType: "application/json; charset=utf-8",
 datatype: "json",
 url: ODataURL,
 beforeSend: function (XMLHttpRequest) {
 XMLHttpRequest.setRequestHeader("Accept", "application/json");
 },
 async: false,
 success: function (data, textStatus, xhr) {
	 
	 // results = data.d.results;
	 
 /*var retrievedLeadState= data.d.results[0].StateCode;*/
 var stateCode = data.d.results[0].StateCode;
 
 var accountState = data.d.results[0].StateCode.Value;
            alert(accountState);
 },
 error: function (xhr, textStatus, errorThrown) { 
 
 Console.log("Error");
 throw errorThrown;
 }
 });
 return results;
 }
 catch (err) {
 throw err;
 }
 },

       

results = checkincident();
         var actif = results[0];

           if(checkincident()==0)
                    {
                        alert('Active');
                   }
           else
                     {
                     alert('Inactive');
                      
					  }
   

is it possible through XRM.Page....?

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    You always can place statecode on the form (even in invisible state) and use following code to get the current value:

    var statecode = Xrm.Page.getAttribute("statecode").getValue();

  • Nando07 Profile Picture
    55 on at

    Hi andrew ,

    thank for your reply .it did work.

    however my client want to it through an ajax call(i don't understand why).

    can you please check my code?

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    So according to your checkincident function, it returns an array of records retrieved but not the statecode. And you compare result of the call with 0 that would never work. Good luck.

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 72 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 29 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans