Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

How to link a Task to a record in a custom table using the API

(0) ShareShare
ReportReport
Posted on by 5

We have created a custum tabel Archiefstuk to hold metadata of a digitial archive stored in an old system.

I have created a custom field in de table Tasks, a lookup file to this table Archiefstuk.

I was able (with some hickups and forced to use the classic mode) to add this lookup field to a task-form and select one of the existing Archiefstuk-records to the task.

I also want to do this using the web-api, but this fails.

After a long time of trials and errors i'm stuck. Please help.

I created the same custum field in the table Accounts, at the same way i did for Tasks, so both tables have a lookup field Archiefstuk that links tot my custum table Archefstuks and for both tables I have a form that allows me to lookup and set that field.

Using the web API, I can set the lookup field on accounts to a value a want:

POST https://******.crm4.dynamics.com/api/data/v9.1/accounts(f238deaa-afe0-ec11-bb3c-000d3a462b19)/****_archiefstuk/$ref
Content-Type: application/json
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
{
"@odata.id": "https://******.crm4.dynamics.com/api/data/v9.1/****_archiefstuks(49b58f1b-09fe-ec11-82e5-000d3a4408c1)"
}
Above succeeds and links the account to this Archiefstuk 

For Task I dit the same:
POST https://******.crm4.dynamics.com/api/data/v9.1/tasks(767d2603-86e1-ec11-bb3c-000d3a462b19)/****_archiefstuk/$ref
Content-Type: application/json
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
{
"@odata.id": "https://******.crm4.dynamics.com/api/data/v9.1/****_archiefstuks(49b58f1b-09fe-ec11-82e5-000d3a4408c1)"
}
Above fails with result:
error":{
"code": "0x8006088a",
"message": "The URI segment '$ref' is invalid after the segment '****_archiefstuk'."
}

In my C#-code I used code to PATCH records, and i can succesfully patch an account withthis  json body
{
"****_archiefstuk@odata.bind", "/****_archiefstuks(49b58f1b-09fe-ec11-82e5-000d3a4408c1)"
}


When I do the same for a task, it return an large arrormessage with principal error:
Updatetask failed with a status of 'Bad Request { "error": { "code": "0x0", "message": "An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property '****_archiefstuk' 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.

What am iI missing here, why are accounts and tasks geving different results for ewxactly the same operations?
But more important: how can I link a task (and later also email, phonecall) to my custom table Archiefstuk

  • Guido Preite Profile Picture
    54,075 Moderator on at
    RE: How to link a Task to a record in a custom table using the API

    that kind of difference usually means that the fields/relationships have not been created by importing a solution from one environment to another but they are created manually inside the target environment.

  • Suggested answer
    Paul Greefhorst Profile Picture
    5 on at
    RE: How to link a Task to a record in a custom table using the API

    Found the problem!

    When exporting and importing te solution thats contained the custum fields I got an error, on the entityrelation "xxx_xxx_archiefstuk_task_archiefstuk;
    I looked deeper into the customisations.xml and found out that the tho fields are not identical, although looking via the PowerApps tool they look identical:

    For Account:

    pastedimage1658849177371v1.png

    for Task:

    pastedimage1658849190368v2.png

    But in the section <EntiryRelatonships> I found that the ItemRelatipnships for Ardhiefstuk to accounts differs from the  ItemRelatipnships for Ardhiefstuk to tasks:

    <EntityRelationship Name="king_archiefstuk_account_Account">

    ...<EntityRelationshipRoles>
    <EntityRelationshipRole>
    <NavPaneDisplayOption>UseCollectionName</NavPaneDisplayOption>
    <NavPaneArea>Details</NavPaneArea>
    <NavPaneOrder>10000</NavPaneOrder>
    <NavigationPropertyName>xxxx_account</NavigationPropertyName>
    <RelationshipRoleType>1</RelationshipRoleType>
    </EntityRelationshipRole>
    <EntityRelationshipRole>
    <NavigationPropertyName>xxxx_archiefstuk_account_Account</NavigationPropertyName>
    <RelationshipRoleType>0</RelationshipRoleType>
    </EntityRelationshipRole>
    </EntityRelationshipRoles>

    while  <EntityRelationship Name="king_king_archiefstuk_task_archiefstuk"> has

    <EntityRelationshipRoles>
    <EntityRelationshipRole>
    <NavPaneDisplayOption>UseCollectionName</NavPaneDisplayOption>
    <NavPaneArea>Details</NavPaneArea>
    <NavPaneOrder>10000</NavPaneOrder>
    <NavigationPropertyName>xxxx_archiefstuk_Task</NavigationPropertyName>
    <CustomLabels>
    <CustomLabel description="" languagecode="1043" />
    </CustomLabels>
    <RelationshipRoleType>1</RelationshipRoleType>
    </EntityRelationshipRole>
    <EntityRelationshipRole>
    <NavigationPropertyName>xxxx_xxxx_archiefstuk_task_archiefstuk</NavigationPropertyName>
    <RelationshipRoleType>0</RelationshipRoleType>
    </EntityRelationshipRole>
    </EntityRelationshipRoles>

    WHen I chenge my post voor task from

    POST https://******.crm4.dynamics.com/api/data/v9.1/tasks(767d2603-86e1-ec11-bb3c-000d3a462b19)/xxxx_archiefstuk/$ref

    to

    POST https://******.crm4.dynamics.com/api/data/v9.1/tasks(767d2603-86e1-ec11-bb3c-000d3a462b19)/xxxx_archiefstuk_Task/$ref

    it is working fine this way....

    beats me why those fields that where defined in exactly the same manner differs on this NavigationPropertyName and why that is not visualised inthe  Power Apps-pages...

  • Guido Preite Profile Picture
    54,075 Moderator on at
    RE: How to link a Task to a record in a custom table using the API

    strange, do you have the latest version of XrmToolBox? current one is 1.2022.5.56

    you can install the tool also manually (downloading the package from nuget www.nuget.org/.../, extract as zip and put inside your plugins folder) but probably it's easier to install the managed solution (that you can find under releases inside the GitHub repository).

    However I will investigate your issue with the Tool Library

  • Paul Greefhorst Profile Picture
    5 on at
    RE: How to link a Task to a record in a custom table using the API

    I did look for that: nothing found:

    pastedimage1657795243734v1.png

  • Guido Preite Profile Picture
    54,075 Moderator on at
    RE: How to link a Task to a record in a custom table using the API

    inside the Tool Library of XrmToolBox make sure that the display tools are all checked and search for rest

    it should appear

    2388.xrmtoolbox.png

  • Paul Greefhorst Profile Picture
    5 on at
    RE: How to link a Task to a record in a custom table using the API

    I can't find yuur tool in then XRM-toolbox;

  • Guido Preite Profile Picture
    54,075 Moderator on at
    RE: How to link a Task to a record in a custom table using the API

    for web api and lookups (the @data.bind notation) is used the navigation property of the relationship, not the field logical name

  • Paul Greefhorst Profile Picture
    5 on at
    RE: How to link a Task to a record in a custom table using the API

    That is not the issue, the fields are exactly the same and schema name and logical names  are all lowercase.

  • Guido Preite Profile Picture
    54,075 Moderator on at
    RE: How to link a Task to a record in a custom table using the API

    you can use my tool Dataverse REST Builder to generate the request, it will suggest you the exact field name to use

  • MikeC282 Profile Picture
    2,115 on at
    RE: How to link a Task to a record in a custom table using the API

    Hey bud,

    Check the name of the lookup. It's case sensitive. Which means if you created a lookup field for example with a Display name of:

    "Test Field"

    When you perform the odatabind it's done to new_TestField, as opposed to new_testfield.

    In the patch code for task. Is the name capitalized?

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,041 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,856 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans