I have a relation field with multiple records in it and I display it via a view element. Now I want to have some dynamic sorting by name, or by a number, but with the sorting I dont have some luck. Here is the code without the sorting and prepared for it.
let ActiveRecords := (select 'Line-up' where Zeitaufzeichnung.'Aufzeichnungen Meldung' like "recordings");
let ActiveRecordsbyName := ActiveRecords.Name;
let ActiveRecordsbyAmount := ActiveRecords.'Erarbeiteter Wert';
let AZ := ActiveRecords;
let ZA := ActiveRecords;
let Amount_UP := ActiveRecords;
let Amount_DOWN := ActiveRecords;
let WorkingInIt := ActiveRecords;
switch 'Sortierung Produktion' do
case 1:
AZ
case 2:
ZA
case 3:
Amount_UP
case 4:
Amount_DOWN
default:
WorkingInIt
end
Hi Stefen, in many of my scripts I've managed to get the click to go to the corresponding record, but I haven't been able to solve it in this script. Do you think you could help me?
let me := ((select Deals) order by 'Expected Close').{
image: ShareLink,
offernumber: Offer_Number,
title: Title,
probability: 'Probability %',
company: a_Companies.'Company Name',
value: format(Value, "#,##0.00 #,#0.0"),
exclose: format('Expected Close', "DD MMM YYYY"),
procStatus: number(Status),
stageLabel: if Stage = 1 then
"Prospecting"
else
if Stage = 2 then
"Qualification"
else
if Stage = 3 then
"Proposal"
else
if Stage = 4 then
"Negotiation"
else
if Stage = 5 then
"Won"
else
if Stage = 6 then "Lost" else "Unknown" end
end
end
end
end
end,
stageClass: if Stage = 1 then
"badge-prospecting"
else
if Stage = 2 then
"badge-qualification"
else
if Stage = 3 then
"badge-proposal"
else
if Stage = 4 then
"badge-negotiation"
else
if Stage = 5 then
"badge-won"
else
if Stage = 6 then "badge-lost" else "badge-default" end
end
end
end
end
end,
statuslight: if Stage = 5 then
"Won"
else
if Stage = 6 then
"Lost"
else
let days := number('Expected Close' - today()) / 86400000;
if days < 0 then
"Overdue"
else
if days <= 7 then
"Urgent"
else
if days <= 30 then "Soon" else "On Track" end
end
end
end
end,
statusClass: if Stage = 5 then
"badge-won"
else
if Stage = 6 then
"badge-lost"
else
let days := number('Expected Close' - today()) / 86400000;
if days < 0 then
"badge-overdue"
else
if days <= 7 then
"badge-urgent"
else
if days <= 30 then "badge-soon" else "badge-ontrack" end
end
end
end
end,
idie: Id
};
let css := "<style>
table.rs { width: 100%; border-collapse: collapse; }
table.rs thead th {
position: sticky; top: 0;
background: #f3f6f8;
border-bottom: 1px solid #dfe6ea;
padding: .5rem .6rem;
text-align: left; font-size: 13px;
}
table.rs td {
border-bottom: 1px solid #eef2f4;
padding: .45rem .6rem;
font-size: 13px; vertical-align: middle;
}
table.rs tbody tr:hover { background: #fafcfd; cursor: pointer; }
.badge {
display: inline-block; padding: 0px 6px;
border-radius: 20px; font-size: 10px;
font-weight: 600; white-space: nowrap;
}
.badge-stack { display: flex; flex-direction: column; gap: 2px; }
.badge-prospecting { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.badge-qualification{ background: #f5f3ff; color: #6d28d9; border: 1px solid #ddd6fe; }
.badge-proposal { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.badge-negotiation { background: #fefce8; color: #854d0e; border: 1px solid #fde68a; }
.badge-won { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.badge-lost { background: #f4f4f5; color: #52525b; border: 1px solid #d4d4d8; }
.badge-overdue { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-urgent { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.badge-soon { background: #fefce8; color: #854d0e; border: 1px solid #fde68a; }
.badge-ontrack { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.badge-default { background: #f4f4f5; color: #52525b; border: 1px solid #d4d4d8; }
.img-avatar {
height: 36px; width: 36px;
object-fit: cover; border-radius: 50%;
border: 2px solid #ccc; display: block;
}
.img-empty { color: #ccc; font-size: 11px; }
.value-cell { font-weight: 500; color: #1e3a5f; }
.probability { font-size: 11px; color: #94a3b8; font-weight: 400; margin-top: 2px; }
.company-cell { font-size: 12px; color: #475569; font-weight: 500; }
.timeline { display:flex; align-items:center; padding:4px 0; }
.step { display:flex; flex-direction:column; align-items:center; }
.circle { width:18px; height:18px; border-radius:50%; background:#e2e8f0; color:#999;
display:flex; align-items:center; justify-content:center; font-size:9px; font-weight:700; }
.circle.done { background:#1f8a70; color:white; }
.circle.active { background:#2e6fd8; color:white; }
.steplabel { font-size:9px; margin-top:3px; color:#999; text-align:center; max-width:50px; }
.steplabel.done { color:#1f8a70; }
.steplabel.active { color:#2e6fd8; font-weight:700; }
.line { flex:1; height:2px; background:#e2e8f0; margin-bottom:14px; min-width:20px; }
.line.done { background:#1f8a70; }
</style>";
let htmlTable := "<div><table class='rs'><thead><tr>" + "<th>Image</th>" + "<th>Stage / Status</th>" +
"<th>Offer #</th>" +
"<th>Company</th>" +
"<th>Title</th>" +
"<th>Value</th>" +
"<th>Close</th>" +
"<th>Milestones</th>" +
"</tr></thead><tbody>";
let rows := "";
for c in me do
if c.statuslight = "Urgent" then
let rid := text(c.idie);
let onclick := "ui.popupRecord('Deals', '" + rid + "')";
let ps := c.procStatus;
let c1 := if ps = 2 then
"active"
else
if ps > 2 then "done" else "" end
end;
let l1 := if ps > 2 then "done" else "" end;
let c2 := if ps = 7 then
"active"
else
if ps > 7 then "done" else "" end
end;
let l2 := if ps > 7 then "done" else "" end;
let c3 := if ps = 9 then
"active"
else
if ps > 9 then "done" else "" end
end;
let timelineHtml := "<div class='timeline'>" + "<div class='step'>" + "<div class='circle " + c1 +
"'>✓</div>" +
"<div class='steplabel " +
c1 +
"'>RFQ Sent</div>" +
"</div>" +
"<div class='line " +
l1 +
"'></div>" +
"<div class='step'>" +
"<div class='circle " +
c2 +
"'>✓</div>" +
"<div class='steplabel " +
c2 +
"'>PO Issued</div>" +
"</div>" +
"<div class='line " +
l2 +
"'></div>" +
"<div class='step'>" +
"<div class='circle " +
c3 +
"'>✓</div>" +
"<div class='steplabel " +
c3 +
"'>Closed</div>" +
"</div>" +
"</div>";
let imgHtml := if c.image != null and c.image != "" then
"<img class='img-avatar' src='" + c.image + "'/>"
else
"<span class='img-empty'>—</span>"
end;
let badgesHtml := "<div class='badge-stack'>" + "<span class='badge " + c.stageClass + "'>" +
c.stageLabel +
"</span>" +
"<span class='badge " +
c.statusClass +
"'>" +
c.statuslight +
"</span>" +
"</div>";
rows := rows + "<tr onclick='" + onclick + "' style='cursor:pointer;'>" + "<td>" + imgHtml +
"</td>" +
"<td>" +
badgesHtml +
"</td>" +
"<td>" +
c.offernumber +
"</td>" +
"<td class='company-cell'>" +
text(c.company) +
"</td>" +
"<td>" +
c.title +
"<br/><span class='probability'>Probability: " +
text(c.probability) +
"%</span></td>" +
"<td class='value-cell'>" +
text(c.value) +
"</td>" +
"<td class='value-cell'>" +
text(c.exclose) +
"</td>" +
"<td>" +
timelineHtml +
"</td>" +
"</tr>"
end
end;
html(css + htmlTable + rows + "</tbody></table></div>")
Fred
1 mth ago
Reported - view
check out great Dashboard Template for what you can do with HTML and Ninox.