Skip to content

Commit c413ff5

Browse files
authored
Zoho CRM - support picklist fields (#14974)
* allow picklist fields * pnpm-lock.yaml * update * updates
1 parent 3c2d4d6 commit c413ff5

File tree

5 files changed

+73
-19
lines changed

5 files changed

+73
-19
lines changed

components/zoho_crm/actions/common/common-objects.mjs

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,33 @@ export default {
2828
&& !field.system_mandatory
2929
&& field.operation_type[`api_${type}`]
3030
&& ![
31-
"picklist",
3231
"lookup",
3332
"ownerlookup",
3433
"profileimage",
3534
].includes(field.data_type));
3635
},
37-
getType(dataType) {
36+
getType({
37+
data_type: dataType, json_type: jsonType,
38+
}) {
39+
let type;
3840
switch (dataType) {
3941
case "boolean":
40-
return "boolean";
42+
type = "boolean";
43+
break;
4144
case "integer":
42-
return "integer";
45+
type = "integer";
46+
break;
4347
case "bigint":
44-
return "integer";
48+
type = "integer";
49+
break;
4550
default:
46-
return "string";
51+
type = "string";
52+
break;
53+
};
54+
if (jsonType === "jsonarray") {
55+
return `${type}[]`;
4756
}
57+
return type;
4858
},
4959
getRequiredProps(moduleType, type = "create") {
5060
let props = {};
@@ -138,12 +148,40 @@ export default {
138148
const { fields } = await this.listFields(moduleType);
139149
for (const field of this.filterFields(fields, type)) {
140150
props[field.api_name] = {
141-
type: this.getType(field.data_type),
151+
type: this.getType(field),
142152
label: field.display_label,
143153
optional: true,
144154
};
155+
if (field.pick_list_values?.length) {
156+
props[field.api_name].options = field.pick_list_values.map(({
157+
display_value: label, actual_value: value,
158+
}) => ({
159+
value,
160+
label,
161+
}));
162+
}
145163
}
146164
return props;
147165
},
166+
parseFields(fields) {
167+
if (!fields) {
168+
return;
169+
}
170+
for (const [
171+
key,
172+
value,
173+
] of Object.entries(fields)) {
174+
try {
175+
if (typeof value === "string") {
176+
fields[key] = typeof JSON.parse(value) === "number"
177+
? value
178+
: JSON.parse(value);
179+
}
180+
} catch {
181+
fields[key] = value;
182+
}
183+
}
184+
return fields;
185+
},
148186
},
149187
};

components/zoho_crm/actions/create-object/create-object.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import common from "../common/common-objects.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
23

34
export default {
45
...common,
56
key: "zoho_crm-create-object",
67
name: "Create Object",
78
description: "Create a new object/module entry. [See the documentation](https://www.zoho.com/crm/developer/docs/api/v2/insert-records.html)",
8-
version: "0.3.2",
9+
version: "0.3.3",
910
type: "action",
1011
async additionalProps() {
1112
const requiredProps = this.getRequiredProps(this.moduleType);
@@ -53,12 +54,18 @@ export default {
5354
});
5455
const objectData = {
5556
data: [
56-
object,
57+
this.parseFields(object),
5758
],
5859
};
5960
const res = await zohoCrm.createObject(moduleType, objectData, $);
60-
if (res.data[0].details.id) {
61+
62+
if (res.data[0].code === "SUCCESS") {
6163
$.export("$summary", `Successfully created new object with ID ${res.data[0].details.id}.`);
64+
} else {
65+
if (res.data[0].code === "INVALID_DATA") {
66+
throw new ConfigurationError(`Error: Invalid data for field '${res.data[0].details.api_name}'. Expected data type: ${res.data[0].details.expected_data_type}`);
67+
}
68+
throw new ConfigurationError(res.data[0].message);
6269
}
6370
return res;
6471
},

components/zoho_crm/actions/update-object/update-object.mjs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import zohoCrm from "../../zoho_crm.app.mjs";
22
import common from "../common/common-objects.mjs";
3+
import { ConfigurationError } from "@pipedream/platform";
34

45
export default {
56
...common,
67
key: "zoho_crm-update-object",
78
name: "Update Object",
89
description: "Updates existing entities in the module. [See the documentation](https://www.zoho.com/crm/developer/docs/api/v2/update-records.html)",
9-
version: "0.3.2",
10+
version: "0.3.3",
1011
type: "action",
1112
props: {
1213
...common.props,
@@ -58,13 +59,21 @@ export default {
5859
...otherProps,
5960
});
6061

61-
const response = await zohoCrm.updateObject(
62+
const res = await zohoCrm.updateObject(
6263
moduleType,
6364
recordId,
64-
object,
65+
this.parseFields(object),
6566
$,
6667
);
67-
$.export("$summary", `Successfully updated object with ID ${recordId}.`);
68-
return response;
68+
69+
if (res.data[0].code === "SUCCESS") {
70+
$.export("$summary", `Successfully updated object with ID ${recordId}.`);
71+
} else {
72+
if (res.data[0].code === "INVALID_DATA") {
73+
throw new ConfigurationError(`Error: Invalid data for field '${res.data[0].details.api_name}'. Expected data type: ${res.data[0].details.expected_data_type}`);
74+
}
75+
throw new ConfigurationError(res.data[0].message);
76+
}
77+
return res;
6978
},
7079
};

components/zoho_crm/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/zoho_crm",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"description": "Pipedream Zoho CRM Components",
55
"main": "zoho_crm.app.mjs",
66
"keywords": [
@@ -10,7 +10,7 @@
1010
"homepage": "https://pipedream.com/apps/zoho_crm",
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"dependencies": {
13-
"@pipedream/platform": "^1.2.0",
13+
"@pipedream/platform": "^3.0.3",
1414
"crypto": "^1.0.1",
1515
"lodash.sortby": "^4.7.0"
1616
},

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)