web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Attribute present in the queried form yet it shows there is no such attribute in java script

(0) ShareShare
ReportReport
Posted on by

hello all i am building a java script which will query email entity using regardingobjectId which will matched the incident(Case) guid and will retrieve the following email and update the subject line, yet so simple query i am getting an error where it shows there is no regardingobjectId in Microsoft.Dynamics.CRM.email , i know it must be one of those time where i have overlooked certain portion of the code and it punishing me,yet after spending many hours i came here to post this question , thanks for looking into this .

function toAccessMailContent(executionContext) {
    var formContext = executionContext.getFormContext();
    var caseID = formContext.getAttribute("ticketnumber").getValue();
    var CaseGuid = Xrm.Page.data.entity.getId();
    if (CaseGuid) {
        CaseGuid = CaseGuid.replace("{", "").replace("}", "");
    }
    var emailActivityId;
     Xrm.WebApi.online.retrieveMultipleRecords("email", "?$select=activityid&$filter=regardingobjectid eq "   CaseGuid   "").then(
        function success(results) {
            for (var i = 0; i < results.entities.length; i  ) {
                if (results.entities.length > 0) {
                    emailActivityId = results.entities[i]["activityid"].replace("{", "").replace("}", "");
                }
                else {
                    console.log("no value");
                }
            }
        },
        function (error) {
            Xrm.Utility.alertDialog(error.message);
        }
        
    );
    var entity = {};
    entity.subject = "Case Record Created"   " "   caseID   " "   "Updated from Javascript";
    entity.cts_source = "Created from OOB Workflow   Updated from Java script";

    Xrm.WebApi.online.updateRecord("email", emailActivityId, entity).then(
        function success(result) {
            var updatedEntityId = result.id;
            console.log(updatedEntityId);
        },
        function (error) {
            Xrm.Utility.alertDialog(error.message);
        }
    );
    
}

I have the same question (0)
  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi Subhajit,

    Your query is not correct you have to _regardingobjectid_value instead of regardingobjectid

        Xrm.WebApi.online.retrieveMultipleRecords("email", "?$select=activityid&$filter=_regardingobjectid_value eq " + CaseGuid + "").then(

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hi,

    Use below updated code to check if it works.

    function toAccessMailContent(executionContext) {
        var formContext = executionContext.getFormContext();
        var caseID = formContext.getAttribute("ticketnumber").getValue();
        var CaseGuid = Xrm.Page.data.entity.getId();
        if (CaseGuid) {
            CaseGuid = CaseGuid.replace("{", "").replace("}", "");
        }
        var emailActivityId;
         Xrm.WebApi.online.retrieveMultipleRecords("email", "?$select=activityid&$filter=_regardingobjectid_value eq "   CaseGuid   "").then(
            function success(results) {
                for (var i = 0; i < results.entities.length; i  ) {
                    if (results.entities.length > 0) {
                        emailActivityId = results.entities[i]["activityid"].replace("{", "").replace("}", "");
                    }
                    else {
                        console.log("no value");
                    }
                }
            },
            function (error) {
                Xrm.Utility.alertDialog(error.message);
            }
            
        );
        var entity = {};
        entity.subject = "Case Record Created"   " "   caseID   " "   "Updated from Javascript";
        entity.cts_source = "Created from OOB Workflow   Updated from Java script";
    
        Xrm.WebApi.online.updateRecord("email", emailActivityId, entity).then(
            function success(result) {
                var updatedEntityId = result.id;
                console.log(updatedEntityId);
            },
            function (error) {
                Xrm.Utility.alertDialog(error.message);
            }
        );
        
    }

    for best practice please install Rest Builder Tool to generate web API code.

    Download managed solution from here - https://github.com/jlattimer/CRMRESTBuilder/releases

    install this in your crm instance and then you are good to do. You can generate any web api code which will always work.

    Please mark my answer verified if i were helpful

  • Community Member Profile Picture
    on at

    thanks Mahender for answering my query , although i was not aware i had to write regardingobjectid as _regardingobjectid_value , i used to think use of attributes is similar to defined in the solution set . actually now i am getting the error (entityId is a mandatory Parameter and it cannot be  null.)  . in past i have never faced such issue while retiring the guid of a particular entity using my current code structure. Would u help me out here why i am receiving such bad errors .Thanks for your valuable input .  

  • Community Member Profile Picture
    on at

    thanks Mahender for answering my query , although i was not aware i had to write regardingobjectid as _regardingobjectid_value , i used to think use of attributes is similar to defined in the solution set . actually now i am getting the error (entityId is a mandatory Parameter and it cannot be  null.)  . in past i have never faced such issue while retiring the guid of a particular entity using my current code structure. Would u help me out here why i am receiving such bad errors .Thanks for your valuable input .  

  • Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    Can you paste your updated query here, Update should work fine using simple query like following

    var entity = {};

    entity.subject = "test";

    var emailID="305b75bd-eb09-eb11-a813-000d3af025cb";

    Xrm.WebApi.online.updateRecord("email",emailID, entity).then(

       function success(result) {

           var updatedEntityId = result.id;

       },

       function(error) {

           console.write(error.message);

       }

    );

  • Community Member Profile Picture
    on at

    hi Bipin i am getting the error (Error: entityId is a mandatory Parameter and it cannot be  null.) in past i retrieved the guid value of the context entity in this way, although now it say it is empty . can you please give your valuable input regarding this matter . thanks for taking time to answer this .

  • Community Member Profile Picture
    on at

    yes this is my final code/query i am using in my web resource , actually Mahender you are 100% correct , this simple query should have worked yet i dont why i am getting this error ,

    ---------------------------------------------------------execution code---------------------------------------------------------------------------------

    function toAccessMailContent(executionContext) {

       var formContext = executionContext.getFormContext();

       var caseID = formContext.getAttribute("ticketnumber").getValue();

       var CaseGuid = Xrm.Page.data.entity.getId();

       if (CaseGuid) {

           CaseGuid = CaseGuid.replace("{", "").replace("}", "");

       }

       var emailActivityId;

        Xrm.WebApi.online.retrieveMultipleRecords("email", "?$select=activityid&$filter=_regardingobjectid_value eq " + CaseGuid + "").then(

           function success(results) {

               for (var i = 0; i < results.entities.length; i++) {

                   if (results.entities.length > 0) {

                       emailActivityId = results.entities[i]["activityid"].replace("{", "").replace("}", "");

                   }

                   else {

                       console.log("no value");

                   }

               }

           },

           function (error) {

               Xrm.Utility.alertDialog(error.message);

           }

       );

       var entity = {};

       entity.subject = "Case Record Created" + " " + caseID + " " + "Updated from Javascript";

       entity.cts_source = "Created from OOB Workflow + Updated from Java script";

       Xrm.WebApi.online.updateRecord("email", emailActivityId, entity).then(

           function success(result) {

               var updatedEntityId = result.id;

               console.log(updatedEntityId);

           },

           function (error) {

               Xrm.Utility.alertDialog(error.message);

           }

       );

    }

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    It seems happening because you are making second call out side of first call so when first request is still in process your second call trying to run and activity id is null so I will suggest you to change your code like below:

    function toAccessMailContent(executionContext) {

      var formContext = executionContext.getFormContext();

      var caseID = formContext.getAttribute("ticketnumber").getValue();

      var CaseGuid = Xrm.Page.data.entity.getId();

      if (CaseGuid) {

          CaseGuid = CaseGuid.replace("{", "").replace("}", "");

      }

      var emailActivityId=null;

       Xrm.WebApi.online.retrieveMultipleRecords("email", "?$select=activityid&$filter=_regardingobjectid_value eq " + CaseGuid + "").then(

          function success(results) {

              for (var i = 0; i < results.entities.length; i++) {

                  if (results.entities.length > 0) {

         emailActivityId = results.entities[i]["activityid"];

     var entity = {};

      entity.subject = "Case Record Created" + " " + caseID + " " + "Updated from Javascript";

      entity.cts_source = "Created from OOB Workflow + Updated from Java script";

      Xrm.WebApi.online.updateRecord("email", emailActivityId, entity).then(

          function success(result) {

              var updatedEntityId = result.id;

              console.log(updatedEntityId);

          },

          function (error) {

              Xrm.Utility.alertDialog(error.message);

          }

      );

                  }

                  else {

                      console.log("no value");

                  }

              }

          },

          function (error) {

              Xrm.Utility.alertDialog(error.message);

          }

      );

    }

  • Community Member Profile Picture
    on at

    yes this seems to be the problem , thanks Mahender , all along my second call was calling an entity whose guid was still under progress. Thank you again Mahender for taking down the bug.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 98 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 72

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans