Salesforce Case/Lead Owner - Add Queues to Owner picklist (#1689)

This commit is contained in:
Craig McElroy 2021-04-24 12:25:30 -05:00 committed by GitHub
parent 4d74e1fdea
commit 66d4fe4911
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 4 deletions

View file

@ -140,7 +140,7 @@ export const caseFields = [
name: 'owner',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUsers',
loadOptionsMethod: 'getCaseOwners',
},
default: '',
description: 'The owner of the case.',
@ -303,7 +303,7 @@ export const caseFields = [
name: 'owner',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUsers',
loadOptionsMethod: 'getCaseOwners',
},
default: '',
description: 'The owner of the case.',

View file

@ -251,7 +251,7 @@ export const leadFields = [
name: 'owner',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUsers',
loadOptionsMethod: 'getLeadOwners',
},
default: '',
description: 'The owner of the lead.',
@ -509,7 +509,7 @@ export const leadFields = [
name: 'owner',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getUsers',
loadOptionsMethod: 'getLeadOwners',
},
default: '',
description: 'The owner of the lead.',

View file

@ -298,6 +298,70 @@ export class Salesforce implements INodeType {
sortOptions(returnData);
return returnData;
},
// Get all the users and case queues to display them to user so that he can
// select them easily
async getCaseOwners(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const qsQueues = {
q: "SELECT Queue.Id, Queue.Name FROM QueuesObject where Queue.Type='Queue' and SobjectType = 'Case'",
};
const queues = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qsQueues);
for (const queue of queues) {
const queueName = queue.Queue.Name;
const queueId = queue.Queue.Id;
returnData.push({
name: `Queue: ${queueName}`,
value: queueId,
});
}
const qsUsers = {
q: 'SELECT id, Name FROM User',
};
const users = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qsUsers);
const userPrefix = returnData.length > 0 ? 'User: ' : '';
for (const user of users) {
const userName = user.Name;
const userId = user.Id;
returnData.push({
name: userPrefix + userName,
value: userId,
});
}
sortOptions(returnData);
return returnData;
},
// Get all the users and lead queues to display them to user so that he can
// select them easily
async getLeadOwners(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const qsQueues = {
q: "SELECT Queue.Id, Queue.Name FROM QueuesObject where Queue.Type='Queue' and SobjectType = 'Lead'",
};
const queues = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qsQueues);
for (const queue of queues) {
const queueName = queue.Queue.Name;
const queueId = queue.Queue.Id;
returnData.push({
name: `Queue: ${queueName}`,
value: queueId,
});
}
const qsUsers = {
q: 'SELECT id, Name FROM User',
};
const users = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qsUsers);
const userPrefix = returnData.length > 0 ? 'User: ' : '';
for (const user of users) {
const userName = user.Name;
const userId = user.Id;
returnData.push({
name: userPrefix + userName,
value: userId,
});
}
sortOptions(returnData);
return returnData;
},
// Get all the lead sources to display them to user so that he can
// select them easily
async getLeadSources(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {