-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
133 lines (109 loc) · 3.76 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const api = require("./famark-cloud");
const promptSync = require("prompt-sync");
const prompt = promptSync();
async function main() {
//Assigning Credentials
const domainName = prompt("Enter Domain Name: ");
const userName = prompt("Enter UserName: ");
const password = prompt("Enter Password: ");
const sessionId = await getSessionId(domainName, userName, password);
if (sessionId == null) {
console.log("Login Failed!");
return;
}
let ans = prompt("Do you want to create a new record? (Y or N): ");
while (ans == "Y" || ans == "y") {
const firstName = prompt("Enter First Name: ");
const lastName = prompt("Enter Last Name: ");
const phone = prompt("Enter Phone: ");
const email = prompt("Enter Email: ")
const contactRecord = {
FirstName: firstName,
LastName: lastName,
Phone: phone,
Email: email
};
const businessContactId = await api.postData(
"/Business_Contact/CreateRecord",
JSON.stringify(contactRecord),
sessionId
);
console.log("Created RecordId: " + businessContactId);
ans = prompt("Do you want to create a new record? (Y or N): ");
}
//Retrieving Business_Contact records
const retrieveMultipleQuery = {
Columns: "FullName, Phone, Email, Business_ContactId",
OrderBy: "FullName"
};
const businessContacts = await api.postData(
"/Business_Contact/RetrieveMultipleRecords",
JSON.stringify(retrieveMultipleQuery),
sessionId
);
for (let i = 0; i < businessContacts.length; i++) {
console.log(businessContacts[i]);
}
//Update Contact
ans = prompt("Do you want to update a record? (Y or N): ");
if (ans == "Y" || ans == "y") {
const contactId = prompt("Enter ContactId: ");
const firstName = prompt("Enter First Name: ");
const lastName = prompt("Enter Last Name: ");
const phone = prompt("Enter Phone: ");
const email = prompt("Enter Email: ")
const contactRecord = {
FirstName: firstName,
LastName: lastName,
Phone: phone,
Email: email,
Business_ContactId: contactId
};
const businessContactId = await api.postData(
"/Business_Contact/UpdateRecord",
JSON.stringify(contactRecord),
sessionId
);
//Retrieve Single Record (Updated Record by Id)
if (businessContactId != null) {
const retrieveRecordQuery = {
Columns: "FullName, Phone, Email, Business_ContactId",
Business_ContactId: contactId
};
const updatedContact = await api.postData(
"/Business_Contact/RetrieveRecord",
JSON.stringify(retrieveRecordQuery),
sessionId
);
console.log("Updated Record:-");
console.log(updatedContact);
}
}
ans = prompt("Do you want to delete a record? (Y or N): ");
if (ans == "Y" || ans == "y") {
const contactId = prompt("Enter ContactId: ");
const deleteRecordDate = {
Business_ContactId: contactId
};
await api.postData(
"/Business_Contact/DeleteRecord",
JSON.stringify(deleteRecordDate),
sessionId
);
console.log("Record Deleted!");
}
}
async function getSessionId(domainName, userName, password) {
const credential = {
DomainName: domainName,
UserName: userName,
Password: password,
};
return await api.postData(
"/Credential/Connect",
JSON.stringify(credential),
null
);
}
//calling main method
main();