Skip to content

Commit

Permalink
remove subsidiary dependency for non oneworld license users
Browse files Browse the repository at this point in the history
  • Loading branch information
SushilMallRC committed Oct 15, 2024
1 parent fbc637a commit bcde3e9
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions src/adapters/netsuite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,23 @@ async function findContact({ user, authHeader, phoneNumber, overridingFormat })
async function createCallLog({ user, contactInfo, authHeader, callLog, note, additionalSubmission }) {
try {
const title = callLog.customSubject ?? `${callLog.direction} Call ${callLog.direction === 'Outbound' ? 'to' : 'from'} ${contactInfo.name}`;
const subsidiary = await axios.post(
`https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql`,
{
q: `SELECT * FROM Subsidiary WHERE id = ${user?.platformAdditionalInfo?.subsidiaryId}`
},
{
headers: { 'Authorization': authHeader, 'Content-Type': 'application/json', 'Prefer': 'transient' }
});
const timeZone = getTimeZone(subsidiary.data.items[0]?.country, subsidiary.data.items[0]?.state);
const callStartTime = moment(moment(callLog.startTime).toISOString()).tz(timeZone);
const subsidiaryId = user?.platformAdditionalInfo?.subsidiaryId;
let callStartTime = moment(moment(callLog.startTime).toISOString());
/**
* Users without a OneWorld license do not have access to subsidiaries.
*/
if (subsidiaryId !== undefined && subsidiaryId !== '') {
const subsidiary = await axios.post(
`https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql`,
{
q: `SELECT * FROM Subsidiary WHERE id = ${user?.platformAdditionalInfo?.subsidiaryId}`
},
{
headers: { 'Authorization': authHeader, 'Content-Type': 'application/json', 'Prefer': 'transient' }
});
const timeZone = getTimeZone(subsidiary.data.items[0]?.country, subsidiary.data.items[0]?.state);
callStartTime = moment(moment(callLog.startTime).toISOString()).tz(timeZone);
}
const callEndTime = moment(callStartTime).add(callLog.duration, 'seconds');
const formatedStartTime = callStartTime.format('YYYY-MM-DD HH:mm:ss');
const formatedEndTime = callEndTime.format('YYYY-MM-DD HH:mm:ss');
Expand Down Expand Up @@ -486,6 +493,7 @@ async function createContact({ user, authHeader, phoneNumber, newContactName, ne
try {
const nameParts = splitName(newContactName);
let contactId = 0;
const subsidiaryId = user.platformAdditionalInfo?.subsidiaryId;
switch (newContactType) {
case 'contact':
let companyId = 0;
Expand All @@ -503,12 +511,15 @@ async function createContact({ user, authHeader, phoneNumber, newContactName, ne
companyId = companyInfo.data.items[0].id;
}
else {
let companyPostBody = {
companyName: 'RingCentral_CRM_Extension_Placeholder_Company',
comments: "This company was created automatically by the RingCentral Unified CRM Extension. Feel free to edit, or associate this company's contacts to more appropriate records.",
};
if (subsidiaryId !== undefined && subsidiaryId !== '') {
companyPostBody.subsidiary = { id: subsidiaryId };
}
const createCompany = await axios.post(`https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/record/v1/customer`,
{
companyName: 'RingCentral_CRM_Extension_Placeholder_Company',
comments: "This company was created automatically by the RingCentral Unified CRM Extension. Feel free to edit, or associate this company's contacts to more appropriate records.",
subsidiary: { id: user.platformAdditionalInfo?.subsidiaryId }
}
companyPostBody
,
{
headers: { 'Authorization': authHeader, 'Content-Type': 'application/json' }
Expand All @@ -520,9 +531,11 @@ async function createContact({ user, authHeader, phoneNumber, newContactName, ne
middleName: nameParts.middleName,
lastName: nameParts.lastName,
phone: phoneNumber || '',
company: { id: companyId },
subsidiary: { id: user.platformAdditionalInfo?.subsidiaryId }
company: { id: companyId }
};
if (subsidiaryId !== undefined && subsidiaryId !== '') {
contactPayLoad.subsidiary = { id: subsidiaryId };
}
const createContactRes = await axios.post(
`https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/record/v1/contact`,
contactPayLoad
Expand Down Expand Up @@ -551,10 +564,12 @@ async function createContact({ user, authHeader, phoneNumber, newContactName, ne
middleName: nameParts.middleName,
lastName: nameParts.lastName.length > 0 ? nameParts.lastName : nameParts.firstName,
phone: phoneNumber || '',
isPerson: true,
subsidiary: { id: user.platformAdditionalInfo?.subsidiaryId }
isPerson: true

};
if (subsidiaryId !== undefined && subsidiaryId !== '') {
customerPayLoad.subsidiary = { id: subsidiaryId };
}
try {
const createCustomerRes = await axios.post(
`https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/record/v1/customer`,
Expand Down

0 comments on commit bcde3e9

Please sign in to comment.