Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

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

Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Attribute present in the queried form yet it shows there is no such attribute in java script

    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.

  • Verified answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Attribute present in the queried form yet it shows there is no such attribute in java script

    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
    Community Member Microsoft Employee on at
    RE: Attribute present in the queried form yet it shows there is no such attribute in java script

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

           }

       );

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Attribute present in the queried form yet it shows there is no such attribute in java script

    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 .

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Attribute present in the queried form yet it shows there is no such attribute in java script

    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
    Community Member Microsoft Employee on at
    RE: Attribute present in the queried form yet it shows there is no such attribute in java script

    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
    Community Member Microsoft Employee on at
    RE: Attribute present in the queried form yet it shows there is no such attribute in java script

    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 .  

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Attribute present in the queried form yet it shows there is no such attribute in java script

    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

  • Verified answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Attribute present in the queried form yet it shows there is no such attribute in java script

    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(

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans