Hello,
I'm trying to use to new Portal's Web API to create portal comments in entity adx_portalcomments.
This entity has a custom field, abc_contactid (not required field), which is a lookup to the contact entity.
The record is created successfully if I don't specify this contact field, but it doesn't work if I try to associate a contact with abc_contactid.
- My first attempt was to try and create a record like this:
webapi.safeAjax({
type: 'POST',
url: '/_api/adx_portalcomments',
contentType: 'application/json',
data: JSON.stringify({
'subject': 'Test',
'description': 'test...',
'regardingobjectid_incident@odata.bind': '/incidents(00000000-0000-0000-0000-000000000001)',
'abc_contactid@odata.bind': '/contacts(00000000-0000-0000-0000-000000000002)'
}),
success: function (res, status, xhr) {
console.log('OK');
},
error: function () {
console.error('Error');
}
});
Then I get a "Bad Request" error: "An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'abc_contactid' 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."
It is to be noted that the regardingobjectid field works perfectly!
I also tried with 'abc_ContactId@odata.bind': '/_api/contacts(00000000-0000-0000-0000-000000000002)', which is the schema name of the field.
// 1. Create the record.
webapi.safeAjax({
type: 'POST',
url: '/_api/adx_portalcomments',
contentType: 'application/json',
data: JSON.stringify({
'subject': 'Test',
'description': 'test...',
'regardingobjectid_incident@odata.bind': '/incidents(00000000-0000-0000-0000-000000000001)'
}),
success: function (res, status, xhr) {
console.log('Portal comment created');
// 2. Associate the new record with the contact.
var entityId = xhr.getResponseHeader('entityId');
webapi.safeAjax({
type: 'POST',
url: '/_api/adx_portalcomments(' + entityId + ')/abc_Contact_adx_PortalComment_ContactId/$ref',
contentType: 'application/json',
data: JSON.stringify({
'@odata.id': '/contacts(00000000-0000-0000-0000-000000000002)'
}),
success: function (res, status, xhr) {
console.log('contact associated with the portal comment');
},
error: function () {
console.error('Error');
}
});
},
error: function () {
console.error('Error');
}
});
The records is created successfully, but then when I try to make the association, I get the error "Resource not found for the segment adx_portalcomments.".
Am I doing something wrong? Or is there something not yet implemented?
Thanks!