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....?

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: check current record active javascript

    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.

  • Nando07 Profile Picture
    Nando07 55 on at
    RE: check current record active javascript

    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?

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: check current record active javascript

    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();

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans