Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed null or undefined value for lookup field #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/dataverse-ify/odataify/odataifyFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export async function odataifyFields(

switch (fieldInfo.fieldType) {
case "[object Undefined]":
// When setting a value to undefined it must be null when sent to the WebApi
output[field] = null;
case "[object Null]": {
addNullValueToOutput(field, metadata, output);
break;
}
case "[object Array]":
{
// Array of Activity Parties or enums
Expand Down Expand Up @@ -65,6 +66,18 @@ export async function odataifyFields(
return true;
}

async function addNullValueToOutput(field: string, metadata: EntityWebApiMetadata, output: IEntity) {
// When setting a value to undefined it must be null when sent to the WebApi
output[field] = null;

// if lookup field, use the Schema Name from navigation
const navigation = caseInsensitiveSearch(field, metadata.navigation as Dictionary<string[]>);
if (navigation) {
output[navigation.key] = null;
delete output[field];
}
}

async function addEntityReferenceToOutput(
entityRef: EntityReference,
field: string,
Expand Down