feat(vtiger-crm): add create lead action
This commit is contained in:
@@ -0,0 +1,395 @@
|
||||
export const fields = [
|
||||
{
|
||||
label: 'Salutation',
|
||||
key: 'salutation',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Mr.', value: 'Mr.' },
|
||||
{ label: 'Ms.', value: 'Ms.' },
|
||||
{ label: 'Mrs.', value: 'Mrs.' },
|
||||
{ label: 'Dr.', value: 'Dr.' },
|
||||
{ label: 'Prof.', value: 'Prof.' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'First Name',
|
||||
key: 'firstName',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Last Name',
|
||||
key: 'lastName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Company',
|
||||
key: 'company',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Primary Email',
|
||||
key: 'primaryEmail',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Office Phone',
|
||||
key: 'officePhone',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Designation',
|
||||
key: 'designation',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listLeadOptions',
|
||||
},
|
||||
{
|
||||
name: 'parameters.designation',
|
||||
value: 'designation',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Mobile Phone',
|
||||
key: 'mobilePhone',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Industry',
|
||||
key: 'industry',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listLeadOptions',
|
||||
},
|
||||
{
|
||||
name: 'parameters.industry',
|
||||
value: 'industry',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Website',
|
||||
key: 'website',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Annual Revenue',
|
||||
key: 'annualRevenue',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Lead Source',
|
||||
key: 'leadSource',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listLeadOptions',
|
||||
},
|
||||
{
|
||||
name: 'parameters.leadSource',
|
||||
value: 'leadsource',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Lead Status',
|
||||
key: 'leadStatus',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listLeadOptions',
|
||||
},
|
||||
{
|
||||
name: 'parameters.leadStatus',
|
||||
value: 'leadstatus',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Assigned To',
|
||||
key: 'assignedTo',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Fax',
|
||||
key: 'fax',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Number of Employees',
|
||||
key: 'numberOfEmployees',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Twitter Username',
|
||||
key: 'twitterUsername',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Record Currency',
|
||||
key: 'recordCurrency',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listRecordCurrencies',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Email Opt-in',
|
||||
key: 'emailOptin',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listLeadOptions',
|
||||
},
|
||||
{
|
||||
name: 'parameters.emailOptin',
|
||||
value: 'emailoptin',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'SMS Opt-in',
|
||||
key: 'smsOptin',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listLeadOptions',
|
||||
},
|
||||
{
|
||||
name: 'parameters.smsOptin',
|
||||
value: 'smsoptin',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Language',
|
||||
key: 'language',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listLeadOptions',
|
||||
},
|
||||
{
|
||||
name: 'parameters.language',
|
||||
value: 'language',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Source Campaign',
|
||||
key: 'sourceCampaign',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listCampaignSources',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Country',
|
||||
key: 'country',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listLeadOptions',
|
||||
},
|
||||
{
|
||||
name: 'parameters.country',
|
||||
value: 'country',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Street',
|
||||
key: 'street',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'PO Box',
|
||||
key: 'poBox',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Postal Code',
|
||||
key: 'postalCode',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'City',
|
||||
key: 'city',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'State',
|
||||
key: 'state',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listLeadOptions',
|
||||
},
|
||||
{
|
||||
name: 'parameters.state',
|
||||
value: 'state',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Description',
|
||||
key: 'description',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Lead Image',
|
||||
key: 'leadImage',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
];
|
@@ -0,0 +1,88 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
import { fields } from './fields.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create lead',
|
||||
key: 'createLead',
|
||||
description: 'Create a new lead.',
|
||||
arguments: fields,
|
||||
|
||||
async run($) {
|
||||
const {
|
||||
salutation,
|
||||
firstName,
|
||||
lastName,
|
||||
company,
|
||||
primaryEmail,
|
||||
officePhone,
|
||||
designation,
|
||||
mobilePhone,
|
||||
industry,
|
||||
website,
|
||||
annualRevenue,
|
||||
leadSource,
|
||||
leadStatus,
|
||||
assignedTo,
|
||||
fax,
|
||||
numberOfEmployees,
|
||||
twitterUsername,
|
||||
recordCurrency,
|
||||
emailOptin,
|
||||
smsOptin,
|
||||
language,
|
||||
sourceCampaign,
|
||||
country,
|
||||
street,
|
||||
poBox,
|
||||
postalCode,
|
||||
city,
|
||||
state,
|
||||
description,
|
||||
leadImage,
|
||||
} = $.step.parameters;
|
||||
|
||||
const elementData = {
|
||||
salutationtype: salutation,
|
||||
firstname: firstName,
|
||||
lastname: lastName,
|
||||
company: company,
|
||||
email: primaryEmail,
|
||||
phone: officePhone,
|
||||
designation: designation,
|
||||
mobile: mobilePhone,
|
||||
industry: industry,
|
||||
website: website,
|
||||
annualrevenue: annualRevenue,
|
||||
leadsource: leadSource,
|
||||
leadstatus: leadStatus,
|
||||
assigned_user_id: assignedTo || $.auth.data.userId,
|
||||
fax: fax,
|
||||
noofemployees: numberOfEmployees,
|
||||
primary_twitter: twitterUsername,
|
||||
record_currency_id: recordCurrency,
|
||||
emailoptin: emailOptin,
|
||||
smsoptin: smsOptin,
|
||||
language: language,
|
||||
source_campaign: sourceCampaign,
|
||||
country: country,
|
||||
lane: street,
|
||||
pobox: poBox,
|
||||
code: postalCode,
|
||||
city: city,
|
||||
state: state,
|
||||
description: description,
|
||||
imagename: leadImage,
|
||||
};
|
||||
|
||||
const body = {
|
||||
operation: 'create',
|
||||
sessionName: $.auth.data.sessionName,
|
||||
element: JSON.stringify(elementData),
|
||||
elementType: 'Leads',
|
||||
};
|
||||
|
||||
const response = await $.http.post('/webservice.php', body);
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
||||
},
|
||||
});
|
@@ -1,4 +1,5 @@
|
||||
import createLead from './create-lead/index.js';
|
||||
import createOpportunity from './create-opportunity/index.js';
|
||||
import createTodo from './create-todo/index.js';
|
||||
|
||||
export default [createOpportunity, createTodo];
|
||||
export default [createLead, createOpportunity, createTodo];
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import listCampaignSources from './list-campaign-sources/index.js';
|
||||
import listContacts from './list-contacts/index.js';
|
||||
import listLeadOptions from './list-lead-options/index.js';
|
||||
import listMilestones from './list-milestones/index.js';
|
||||
import listOpportunityOptions from './list-opportunity-options/index.js';
|
||||
import listOrganizations from './list-organizations/index.js';
|
||||
@@ -13,6 +14,7 @@ import listTodoOptions from './list-todo-options/index.js';
|
||||
export default [
|
||||
listCampaignSources,
|
||||
listContacts,
|
||||
listLeadOptions,
|
||||
listMilestones,
|
||||
listOpportunityOptions,
|
||||
listOrganizations,
|
||||
|
@@ -0,0 +1,56 @@
|
||||
export default {
|
||||
name: 'List lead options',
|
||||
key: 'listLeadOptions',
|
||||
|
||||
async run($) {
|
||||
const leadOptions = {
|
||||
data: [],
|
||||
};
|
||||
const {
|
||||
designation,
|
||||
industry,
|
||||
leadSource,
|
||||
leadStatus,
|
||||
emailOptin,
|
||||
smsOptin,
|
||||
language,
|
||||
country,
|
||||
state,
|
||||
} = $.step.parameters;
|
||||
|
||||
const picklistFields = [
|
||||
designation,
|
||||
industry,
|
||||
leadSource,
|
||||
leadStatus,
|
||||
emailOptin,
|
||||
smsOptin,
|
||||
language,
|
||||
country,
|
||||
state,
|
||||
];
|
||||
|
||||
const params = {
|
||||
operation: 'describe',
|
||||
sessionName: $.auth.data.sessionName,
|
||||
elementType: 'Leads',
|
||||
};
|
||||
|
||||
const { data } = await $.http.get(`/webservice.php`, { params });
|
||||
|
||||
if (data.result.fields?.length) {
|
||||
for (const field of data.result.fields) {
|
||||
if (picklistFields.includes(field.name)) {
|
||||
field.type.picklistValues.map((item) =>
|
||||
leadOptions.data.push({
|
||||
value: item.value,
|
||||
name: item.label,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return leadOptions;
|
||||
},
|
||||
};
|
@@ -5,6 +5,8 @@ items:
|
||||
desc: Create a new opportunity.
|
||||
- name: Create todo
|
||||
desc: Create a new todo.
|
||||
- name: Create lead
|
||||
desc: Create a new lead.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
|
Reference in New Issue
Block a user