mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 14:44:05 -08:00
Add method to create data from parameters
This commit is contained in:
parent
348afdaf5c
commit
5d2f2ff493
|
@ -44,3 +44,29 @@ export async function cockpitApiRequest(this: IExecuteFunctions | IExecuteSingle
|
||||||
throw new Error(`Cockpit error [${error.statusCode}]: ` + errorMessage);
|
throw new Error(`Cockpit error [${error.statusCode}]: ` + errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createDataFromParameters(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, itemIndex: number): IDataObject {
|
||||||
|
const dataFieldsAreJson = this.getNodeParameter('jsonDataFields', itemIndex) as boolean;
|
||||||
|
|
||||||
|
if (dataFieldsAreJson) {
|
||||||
|
// Parameters are defined as JSON
|
||||||
|
return JSON.parse(this.getNodeParameter('dataFieldsJson', itemIndex, {}) as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parameters are defined in UI
|
||||||
|
return unpackUiDataFields(this.getNodeParameter('dataFieldsUi', itemIndex, {}) as IDataObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
function unpackUiDataFields(uiDataFields: IDataObject): IDataObject {
|
||||||
|
const unpacked: IDataObject = {};
|
||||||
|
|
||||||
|
if (uiDataFields.field === undefined) {
|
||||||
|
return unpacked;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const field of uiDataFields!.field as IDataObject[]) {
|
||||||
|
unpacked[field!.name as string] = field!.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return unpacked;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue