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 CRM (Archived)

CRM Web API, Entity Based Restriction

(0) ShareShare
ReportReport
Posted on by 402

Hi to all,

I have some doubts that CRM has some restrictions on Web API functions on call. Let me introduce briefly.

I can create a record in my custom entity with below-stated parameters without error.

            var dataCamp =
            {
                "new_name": "Test Title",
                "new_AccountId@odata.bind": "/accounts("86F10EB5-09E4-E811-A94F-000D3AB6413D)",
            };
            Xrm.WebApi.createRecord("new_testentity", dataCamp).then(
            ...


But when I want to create a record on OOB - Campaign Response then I have got an error. 

var dataCamp =
            {
                "subject": Test Title,
                "regardingobjectid_campaign@odata.bind": "/campaigns(" + campaignId + ")",
                "new_AppointmentId@odata.bind": "/appointments(fd288fdd-abe8-e811-a950-000d3ab6488a)"
            };
            Xrm.WebApi.createRecord("new_testentity", dataCamp).then(
            ...

Error Message is:
An undeclared property 'new_AppointmentId' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.

I have all controlled; schema name of lookup, relations, and the name of the relations from .XML files and nothing is wrong.

The funny part is: I can create a "Campaign Response" with Regarding lookup if I remove the new custom lookup on my query)

So you dear guys and ladies, could you please check my upper statements to prevent some missing points? 

If you can try in your system especially on Campaign Response to create, it would be so great to compare.

Thanks in advance, Seren.

*This post is locked for comments

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

    Hello,

    Have you checked CrmRestBuilder by a chance? github.com/.../releases

  • Seren S Profile Picture
    402 on at

    Hi Andrew,

    Unfortunately I have tried but no lock. It produces the same query structure with mine.

    Do you have any idea? It could be something else.

  • Rawish Kumar Profile Picture
    13,758 on at

    Hi Seren,

    I have faced this issue multiple times - this error majorly related to the line:

    "new_AppointmentId@odata.bind": "/appointments(fd288fdd-abe8-e811-a950-000d3ab6488a)"

    and to be more precise the "new_AppointmentId" - Please go to your Customization > Entity > look for this field and use the "Schema Name".  Web API strictly looks for casing the field so this might be New_Appointmentid or new_appointmentId etc etc.

  • Seren S Profile Picture
    402 on at

    Hi Rawish,

    I appricate your response but I have already checked the "Schema Name". I also download the Web API OData Metadata and checked this XML too. It is as the same with system but no lock :(

  • Rawish Kumar Profile Picture
    13,758 on at

    Hi Seren,

    Okay lets try to narrow down the issue.

    please confirm if you are able to browse the api :

    orgname.api.crm8.dynamics.com/.../appointments(fd288fdd-abe8-e811-a950-000d3ab6488a)

    also please also try this

    orgname.api.crm8.dynamics.com/.../appointments(fd288fdd-abe8-e811-a950-000d3ab6488a)$select=new_AppointmentId  

    let us know the result.

  • Seren S Profile Picture
    402 on at

    Hi Rawish,

    I can retrieve the Appointment lookup value. No problem. The record exists.

    myorg.crm4.dynamics.com/.../appointments(fd288fdd-abe8-e811-a950-000d3ab6488a)

    new_AppointmentId is not an attribute in Appointment. It is the lookup field in Campaign Response to N:1 to Appointment.

    To check this, I can retrieve any of the Campaign Response and I can see the _new_appointmentid_value in the results.

    myorg.crm4.dynamics.com/.../campaignresponses(49397C8D-D017-E911-A953-000D3AB6488A)

    Then the strange part (which I have doubts about restrictions) is, I can't query to select this record.

    myorg.crm4.dynamics.com/.../campaignresponses(49397C8D-D017-E911-A953-000D3AB6488A)$select=new_AppointmentId

    It returns; "Could not find a property named 'new_AppointmentId' on type 'Microsoft.Dynamics.CRM.campaignresponse'"

    I have tried this in our SANDBOX, PROD and no luck.

    I bet, if you also create a N-1 in Campaign Response to Appointment then you will not retrieve this lookup field via Web API :)

  • Rawish Kumar Profile Picture
    13,758 on at

    Hi Seren,

    It works for me , i could retrieve it using web api url :  passion4dynamicscrm.crm8.dynamics.com/.../campaignresponses(5DE7E6BC-E817-E911-A96A-000D3AF06590)$select=_new_appointmentid_value    

    result :   {"@odata.context":"passion4dynamicscrm.crm8.dynamics.com/.../v9.1$metadata#campaignresponses(_new_appointmentid_value)/$entity","@odata.etag":"W/\"2805575\"","_new_appointmentid_value@OData.Community.Display.V1.FormattedValue":"Test","_new_appointmentid_value@Microsoft.Dynamics.CRM.associatednavigationproperty":"new_appointmentid_CampaignResponse","_new_appointmentid_value@Microsoft.Dynamics.CRM.lookuplogicalname":"appointment","_new_appointmentid_value":"81ece6af-e817-e911-a96a-000d3af06590","activityid":"5de7e6bc-e817-e911-a96a-000d3af06590"}

    also i tried in rest builder and executed the code there by putting result in the alert and i got the name of the appointment when i executed the code then and there!

    I would really suggest you use the rest builder the sample code below:

    var entity = {};

    entity["new_appointmentid@odata.bind"] = "/appointments(5DE7E6BC-E817-E911-A96A-000D3AF06590)";

    entity.lastname = "test";

    var req = new XMLHttpRequest();

    req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/campaignresponses(5DE7E6BC-E817-E911-A96A-000D3AF06590)", true);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    req.onreadystatechange = function() {

       if (this.readyState === 4) {

           req.onreadystatechange = null;

           if (this.status === 204) {

               //Success - No Return Data - Do Something

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send(JSON.stringify(entity));

  • Seren S Profile Picture
    402 on at

    Hi Rawish,

    I truly appreciate for your test. Still no luck with your last sample but at least we found the difference I think.

    Based on your response: it is clearly seen that your response has a relation with associatednavigationproperty but in mine, it doesn't exist.

    {"@odata.context":"myorg.crm4.dynamics.com/.../v9.1$metadata#campaignresponses(_fein_appointmentid_value)/$entity","@odata.etag":"W/\"4932014\"","_fein_appointmentid_value":null,"activityid":"49397c8d-d017-e911-a953-000d3ab6488a"}

    I believe you can retrieve with;

    passion4dynamicscrm.crm8.dynamics.com/.../campaignresponses(5DE7E6BC-E817-E911-A96A-000D3AF06590)$select=_new_appointmentid_value

    and

    passion4dynamicscrm.crm8.dynamics.com/.../campaignresponses(5DE7E6BC-E817-E911-A96A-000D3AF06590)$select=new_AppointmentId

    because it should also works with only attribute name on the select. (It works on my one of custom entity by the way)

    I can't under what is the difference? :(

  • Rawish Kumar Profile Picture
    13,758 on at

    I agree on some custom entity you dont have to do it like "_new_appointmentid_value" simpley new_appointmentid would work , but on almost all out of the box entity you have retrieve value this way only.

    BTW if this doesn't work did you try to utilize out of the box lookup of "Originating Activity" which is a partylist.

  • Seren S Profile Picture
    402 on at

    Hi Rawish,

    Sure I can try. At the same time, could you please try the below-stated CREATE statement in REST BUILDER?

    Regarding_Campaign and Subjects are mandatory. I am so curious about your result.

    var entity = {};

    entity["regardingobjectid_campaign@odata.bind"] = "/campaigns(YOUR GUID OF ONE OF CAMPAIGN)";

    entity.subject = "test";

    entity["new_AppointmentId@odata.bind"] = "/appointments(YOUR GUID OF APPOINTMENT)";

    Xrm.WebApi.online.createRecord("campaignresponse", entity).then(

       function success(result) {

           var newEntityId = result.id;

       },

       function(error) {

           Xrm.Utility.alertDialog(error.message);

       }

    );

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans