Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions n8n-nodes-dataverse-auth/credentials/dataverseAuth.credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,29 @@ export class dataverseAuth implements ICredentialType {
}
}

async DeleteRecord(entityName: string, recordId: string): Promise<void> {
await this.ensureAuthenticated();
if (!this.axiosInstance) throw new Error('Axios instance not available');

const modifiedEntityLogicalName = this.modifyEntityLogicalName(entityName);
const fullApiUrl = `/api/data/v9.2/${modifiedEntityLogicalName}(${recordId})`;

const headers = {
"OData-MaxVersion": "4.0",
"Accept": "application/json",
"Prefer": "odata.include-annotations=*",
};

try {
await this.axiosInstance.delete(fullApiUrl, { headers });
} catch (error: any) {
throw new Error(
`Dataverse API error: ${error.response?.status} - ${error.response?.statusText}. Details: ${JSON.stringify(
error.response?.data
)}`
);
}
}

async ListEntityColumns(entityName: string): Promise<{ columns: any[] }> {
await this.ensureAuthenticated();
Expand Down
22 changes: 18 additions & 4 deletions n8n-nodes-dataverse-auth/nodes/Dataverse.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { globaloptionsetOperations } from "./globaloptionsetOperations";
import { entityLookupOperations } from "./entityLookupOperations";
import { Properties } from "./properties";
import { OperationType } from "./operationType";
import { deleteOperations } from "./deleteOperations";

export class Dataverse implements INodeType {
description: INodeTypeDescription = {
Expand Down Expand Up @@ -49,7 +50,8 @@ export class Dataverse implements INodeType {
...postOperations,
...optionsetOperations,
...globaloptionsetOperations,
...entityLookupOperations
...entityLookupOperations,
...deleteOperations
],
};

Expand Down Expand Up @@ -106,9 +108,6 @@ export class Dataverse implements INodeType {
},
};




async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>
{
const items = this.getInputData();
Expand Down Expand Up @@ -146,6 +145,9 @@ export class Dataverse implements INodeType {
case Operation.POST:
columnsData = await handlePostOperation(this,columnsData, itemIndex, entityName, patch_data);
break;
case Operation.DELETE:
await handleDeleteOperation(this, entityName, itemIndex);
break;
case Operation.OPTIONSET:
query = await handleOptionSetOperation(query, optionset_entityname, optionset_attributename, itemIndex);
break;
Expand Down Expand Up @@ -177,6 +179,18 @@ export class Dataverse implements INodeType {
}
return this.prepareOutputData(returnData);

async function handleDeleteOperation(func:IExecuteFunctions, entityName: string, itemIndex: number) {
const recordId = func.getNodeParameter(Properties.DELETE_RECORDID, itemIndex) as string;
await auth.DeleteRecord(entityName, recordId);
returnData.push({
json: {
success: true,
message: `Record ${recordId} deleted successfully from ${entityName}`,
},
pairedItem: itemIndex,
});
}

async function handleEntityOperation(entityname: string, entity_id: string, entity_name: string, entityName: string, itemIndex: number) {
const modifiedEntityLogicalName = auth.modifyEntityLogicalName(entityname);
const entityquery = `${modifiedEntityLogicalName}?$select=${entity_id},${entity_name}&$orderby=${entity_name} asc`;
Expand Down
35 changes: 35 additions & 0 deletions n8n-nodes-dataverse-auth/nodes/deleteOperations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { INodeProperties } from "n8n-workflow";
import { Operation } from "./operation";
import { Properties } from "./properties";

export const deleteOperations: INodeProperties[] = [
{
displayName: "Entity Name",
name: Properties.ENTITYNAME,
type: "options",
typeOptions: {
loadOptionsMethod: "getEntityList",
},
required: true,
default: "",
displayOptions: {
show: {
operation: [Operation.DELETE],
},
},
description: "Name of the entity to delete from",
},
{
displayName: "Record ID",
name: Properties.DELETE_RECORDID,
type: "string",
required: true,
default: "",
displayOptions: {
show: {
operation: [Operation.DELETE],
},
},
description: "ID of the record to delete",
},
];
15 changes: 8 additions & 7 deletions n8n-nodes-dataverse-auth/nodes/operation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export enum Operation {
GET = "GET",
PATCH = "PATCH",
POST = "POST",
OPTIONSET = "OPTIONSET",
GLOBALOPTIONSET = "GLOBALOPTIONSET",
ENTITY = "ENTITY",
}
GET = "GET",
PATCH = "PATCH",
POST = "POST",
OPTIONSET = "OPTIONSET",
GLOBALOPTIONSET = "GLOBALOPTIONSET",
ENTITY = "ENTITY",
DELETE = "DELETE",
}
5 changes: 5 additions & 0 deletions n8n-nodes-dataverse-auth/nodes/operationOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export const operationOptions : INodeProperties = {
value: Operation.ENTITY,
action: "Retrieve lookup data from table",
},
{
name: "Delete record",
value: Operation.DELETE,
action: "Delete record",
},
],
default: Operation.GET,
};
6 changes: 4 additions & 2 deletions n8n-nodes-dataverse-auth/nodes/properties.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export enum Properties {
//GET
GET_QUERY = "GET_QUERY",
Expand Down Expand Up @@ -27,4 +26,7 @@ export enum Properties {

TYPE = "TYPE",
OPERATION = "OPERATION",
}

//DELETE
DELETE_RECORDID = "delete_recordid",
}
Binary file modified n8n-nodes-dataverse-auth/nodes/resources/image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions n8n-nodes-dataverse-auth/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ The Dataverse node offers several operations, each with specific parameters:
* **Type:** Column.
* **Columns (for COLUMN type):** Specify the columns and their values.

### Delete Record (DELETE)

![alt text](./nodes/resources/image-14.png)

* **Entity Name:** Select the entity (table) from which to delete the record.
* **Record ID:** Provide the ID of the record to be deleted.

### Get Lookup from Option Set Definitions (OPTIONSET)


Expand Down