-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.html
More file actions
109 lines (92 loc) · 3.52 KB
/
widget.html
File metadata and controls
109 lines (92 loc) · 3.52 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script src="https://live.zwidgets.com/js-sdk/1.3/ZohoEmbededAppSDK.min.js"></script>
<style>
body { font-family: Arial; padding: 20px; max-width: 400px; }
label, select, input, button { display: block; width: 100%; margin: 10px 0; padding: 8px; }
h2 { margin-bottom: 20px; }
#status { margin-top: 10px; font-weight: bold; }
</style>
</head>
<body>
<h2>Lead Reassigner</h2>
<label for="sourceUserSelect">Source Owner:</label>
<select id="sourceUserSelect"></select>
<label for="targetUserSelect">Target Owner:</label>
<select id="targetUserSelect"></select>
<label for="qtyInput">Number of Leads to Reassign:</label>
<input type="number" id="qtyInput" min="1" value="5" />
<button onclick="reassignLeads()">Reassign Leads</button>
<div id="status"></div>
<script>
window.allowZohoEmbeddedAppSdk = true;
function loadUsers() {
const status = document.getElementById("status");
status.innerText = "🔄 Loading users...";
let timeout = setTimeout(() => {
status.innerText = "⚠️ Timeout: No user data received after 5 seconds.";
console.warn("getAllUsers API is hanging or unresponsive.");
}, 5000);
ZOHO.CRM.API.getAllUsers()
.then(function(data) {
clearTimeout(timeout);
console.log("getAllUsers response:", data);
const source = document.getElementById("sourceUserSelect");
const target = document.getElementById("targetUserSelect");
if (data && data.users && data.users.length > 0) {
data.users.forEach(user => {
let opt1 = new Option(user.full_name, user.id);
let opt2 = new Option(user.full_name, user.id);
source.add(opt1);
target.add(opt2.cloneNode(true));
});
status.innerText = "✅ Users loaded.";
} else {
status.innerText = "⚠️ No users returned.";
}
})
.catch(function(err) {
clearTimeout(timeout);
console.error("getAllUsers failed:", err);
status.innerText = "❌ Error loading users.";
});
}
function reassignLeads() {
const sourceId = document.getElementById("sourceUserSelect").value;
const targetId = document.getElementById("targetUserSelect").value;
const qty = parseInt(document.getElementById("qtyInput").value, 10);
const status = document.getElementById("status");
if (!sourceId || !targetId || isNaN(qty) || qty <= 0) {
status.innerText = "❌ Please complete all fields correctly.";
return;
}
status.innerText = "⏳ Reassigning leads...";
ZOHO.CRM.FUNCTIONS.execute("Reassign_Leads_With_Calls", {
source_owner_id: sourceId,
target_owner_id: targetId,
num_to_transfer: qty
}).then(function(response) {
if (response && response.details && response.details.output) {
status.innerText = `✅ Done: ${response.details.output.length} leads reassigned.`;
} else {
status.innerText = "⚠️ Unexpected response from function.";
}
}).catch(function(error) {
console.error("Function execution failed", error);
status.innerText = "❌ Error reassigning leads.";
});
}
if (typeof ZOHO !== 'undefined') {
ZOHO.embeddedApp.on("PageLoad", function() {
console.log("ZOHO SDK initialized. Loading users...");
loadUsers();
});
ZOHO.embeddedApp.init();
} else {
document.getElementById("status").innerText = "❌ Not running inside Zoho CRM.";
}
</script>
</body>
</html>