简体   繁体   中英

CRM 9 - Fetch records from a CRM entity based on ID using JavaScript WebResource

I have a entity with multiple records in it. The entity contains 3 fields Parameter Name , Parameter Value , and Contact ID . Contact ID is a lookup field. There are multiple records for a same Contact ID in my CRM Entity.

Now I want to fetch all Parameter Name and Parameter Value from CRM Entity based on the Contact ID .

I am using following code,

var Query = "$select=vrp_parametername&$filter= vrp_contactid eq '" + contactid + "'";
 XrmSvcToolkit.retrieveMultiple({
    entityName: entity ,  
    odataQuery: Query,
    async: false,
    successCallback: successCallback,
    errorCallback: errorCallback
});

But I am getting following error,

Error has occurred in retrieving Response - Error: 400: Bad Request: No property 'vrp_contactid' exists in type 'Microsoft.Xrm.Sdk.Entity' at position 1

Error clearly states that for that particular entity it could not find vrp_contactid field. Why don't you check if field is available. Try using Crm restbuilder and see which condition attribute is available.

You should use _vrp_contactid_value

var Query = "$select=vrp_parametername&$filter=_vrp_contactid_value eq '" + contactid + "'";

Update :

You can use the filter using single valued navigation property, refer my blog on same topic. There is another version of this query below:

var Query = "$select=vrp_parametername&$filter=vrp_contactid/contactid eq '" + contactid + "'";

Read more

I was mixing the Schema Name with Logical Name in CRM in this case. I was using Schema Name in CRM which was why this error was coming.

What I did was simply used the Logical Name in this case and was able to achieved the desired result.

Thank you all for the help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM