Skip to content

Commit 0d5ce5b

Browse files
committed
MakeWidgetKeyUnique - Iterate over all dashboards in a namespace, for each iterate over widgets. Changes widget key if previously encountered
1 parent 6fd946c commit 0d5ce5b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

MDX2JSON/Tests.cls.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,35 @@ do ##class(MDX2JSON.Tests).RenderSpeed()</Description>
150150
Write "Time Average: ",time/Count
151151
]]></Implementation>
152152
</Method>
153+
154+
<Method name="MakeWidgetKeyUnique">
155+
<Description>
156+
Iterate over all dashboards in a namespace, for each iterate over widgets.
157+
Changes widget key if previously encountered</Description>
158+
<ClassMethod>1</ClassMethod>
159+
<Implementation><![CDATA[
160+
set rs = ##class(%DeepSee.Dashboard.Definition).ExtentFunc()
161+
set WidgetKeyList=""
162+
while rs.%Next() {
163+
set Dash = ##class(%DeepSee.Dashboard.Definition).%OpenId(rs.%Get("ID"))
164+
for i=1:1:Dash.widgets.Count() {
165+
set WidgetKey = Dash.widgets.GetAt(i).key
166+
if $LF(WidgetKeyList,WidgetKey) {
167+
write "Duplicate dash: ", rs.%Get("ID"), " oldkey: ", WidgetKey
168+
// generate new randow widget key
169+
do {
170+
set WidgetKey = $R(1000000000)
171+
} while ($LF(WidgetKeyList,WidgetKey)'=0)
172+
set WidgetKeyList = WidgetKeyList _$LB(WidgetKey)
173+
set Dash.widgets.GetAt(i).key = WidgetKey
174+
write "newkey: ", WidgetKey, !
175+
write $System.Status.GetErrorText(Dash.%Save())
176+
} else {
177+
set WidgetKeyList = WidgetKeyList _$LB(WidgetKey)
178+
}
179+
}
180+
}
181+
]]></Implementation>
182+
</Method>
153183
</Class>
154184
</Export>

0 commit comments

Comments
 (0)