Product: Mingcedar Studio DESIGNER
Select a device in a popup: pass the current value and update the original page | Mingcedar Studio
Use two slides to create a device picker. The source passes the current device and updates its text when the popup returns a selection. This example uses page variables and does not write to equipment.
<div class="manual-doc-article manual-doc-article-section"><h2 id="recipe-popup-selection">Popup tutorial: Select a device in a popup: pass the current value and update the original page</h2>
Use two slides to create a device picker. The source passes the current device and updates its text when the popup returns a selection. This example uses page variables and does not write to equipment.
<div class="doc-card-list doc-tutorial">
<article class="doc-card">
<h3 id="recipe-popup-selection-item-1">1. Create the source page and picker</h3>
<p>Create two slides in one PPT. Set Page Codes to overview (source) and pump_picker (popup) in MX Design → Page → Nav Path and save. Code opens pages by Page Code.</p>
<ol>
<li>On overview, insert one text shape and a rectangle button labelled Choose device. On pump_picker, insert one text shape and three rectangle buttons labelled Choose PUMP01, Choose PUMP02 and Cancel.</li>
<li>Open Page Script through MX Design → Scripts → Page Script. Select the appropriate slide before entering its code.</li>
<li>To add a behavior, open MX Design → Behaviors → Browse and drag it from the right-hand catalog to the component node on the left. Use Interactions → Click Script for buttons and Text → Script Text for text shapes. Double-click each added behavior and fill the fields specified below.</li>
</ol>
<ul class="doc-related-links">
<li><a href="/en/ppt/manual/first-screen/">First use: components, behaviors and publishing</a></li>
</ul>
</article>
<article class="doc-card">
<h3 id="recipe-popup-selection-item-2">2. Store the current selection on the source page</h3>
<p>Put this code in overview Page Script. Add Script Text to its text shape, clear the default Setup Script, set Condition to true and Display Text to selectionMessage, then save.</p>
<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>overview → Page Script</span><span class="manual-code-tools"><small>JavaScript</small><button type="button" data-copy-code data-copied="Copied" data-failed="Select and copy the code" aria-label="Copy code: overview → Page Script">Copy code</button><span class="manual-code-status" role="status"></span></span></div><pre tabindex="0" class="docs-code-block shiki github-light" style="background-color:#fff;color:#24292e" tabindex="0"><code><span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> popupSelectedPump </span><span style="color:#D73A49">=</span><span style="color:#032F62"> "PUMP01"</span><span style="color:#24292E">;</span></span>
<span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> selectionMessage </span><span style="color:#D73A49">=</span><span style="color:#032F62"> "Selected: "</span><span style="color:#D73A49"> +</span><span style="color:#24292E"> popupSelectedPump;</span></span></code></pre></div>
<p class="doc-step-result"><strong>Expected result</strong> The source displays Selected: PUMP01.</p>
</article>
<article class="doc-card">
<h3 id="recipe-popup-selection-item-3">3. Open the popup and handle its result</h3>
<p>Put this code in overview’s Choose device Click Script. After the popup closes, then validates the result and updates page variables. Cancel or Escape keeps the original selection.</p>
<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>Choose device button → Click Script</span><span class="manual-code-tools"><small>JavaScript</small><button type="button" data-copy-code data-copied="Copied" data-failed="Select and copy the code" aria-label="Copy code: Choose device button → Click Script">Copy code</button><span class="manual-code-status" role="status"></span></span></div><pre tabindex="0" class="docs-code-block shiki github-light" style="background-color:#fff;color:#24292e" tabindex="0"><code><span class="line"><span style="color:#D73A49">return</span><span style="color:#005CC5"> HQ</span><span style="color:#24292E">.popup.</span><span style="color:#6F42C1">open</span><span style="color:#24292E">(</span><span style="color:#032F62">"pump_picker"</span><span style="color:#24292E">, {</span></span>
<span class="line"><span style="color:#24292E"> parameters: [{ key: </span><span style="color:#032F62">"pump"</span><span style="color:#24292E">, value: popupSelectedPump }],</span></span>
<span class="line"><span style="color:#24292E"> closeOnEscape: </span><span style="color:#005CC5">true</span></span>
<span class="line"><span style="color:#24292E">}).</span><span style="color:#6F42C1">then</span><span style="color:#24292E">(</span><span style="color:#D73A49">function</span><span style="color:#24292E"> (</span><span style="color:#E36209">result</span><span style="color:#24292E">) {</span></span>
<span class="line"><span style="color:#D73A49"> if</span><span style="color:#24292E"> (result </span><span style="color:#D73A49">==</span><span style="color:#005CC5"> null</span><span style="color:#24292E">) </span><span style="color:#D73A49">return</span><span style="color:#24292E">;</span></span>
<span class="line"><span style="color:#D73A49"> if</span><span style="color:#24292E"> (result </span><span style="color:#D73A49">!==</span><span style="color:#032F62"> "PUMP01"</span><span style="color:#D73A49"> &&</span><span style="color:#24292E"> result </span><span style="color:#D73A49">!==</span><span style="color:#032F62"> "PUMP02"</span><span style="color:#24292E">) {</span></span>
<span class="line"><span style="color:#D73A49"> throw</span><span style="color:#D73A49"> new</span><span style="color:#6F42C1"> Error</span><span style="color:#24292E">(</span><span style="color:#032F62">"Unsupported pump selection"</span><span style="color:#24292E">);</span></span>
<span class="line"><span style="color:#24292E"> }</span></span>
<span class="line"><span style="color:#24292E"> popupSelectedPump </span><span style="color:#D73A49">=</span><span style="color:#24292E"> result;</span></span>
<span class="line"><span style="color:#24292E"> selectionMessage </span><span style="color:#D73A49">=</span><span style="color:#032F62"> "Selected: "</span><span style="color:#D73A49"> +</span><span style="color:#24292E"> result;</span></span>
<span class="line"><span style="color:#24292E">});</span></span></code></pre></div>
<p class="doc-step-result"><strong>Expected result</strong> The button opens pump_picker with the current pump parameter. The selection has not changed yet.</p>
</article>
<article class="doc-card">
<h3 id="recipe-popup-selection-item-4">4. Read the incoming value in the popup</h3>
<p>Put this code in pump_picker Page Script. Add Script Text to its text shape, clear the default Setup Script, set Condition to true and Display Text to incomingMessage. The popup reads the source selection through the pump parameter. Missing or unknown parameters display an error and prevent the selection buttons below from returning a device.</p>
<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>pump_picker → Page Script</span><span class="manual-code-tools"><small>JavaScript</small><button type="button" data-copy-code data-copied="Copied" data-failed="Select and copy the code" aria-label="Copy code: pump_picker → Page Script">Copy code</button><span class="manual-code-status" role="status"></span></span></div><pre tabindex="0" class="docs-code-block shiki github-light" style="background-color:#fff;color:#24292e" tabindex="0"><code><span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> incomingPump </span><span style="color:#D73A49">=</span><span style="color:#6F42C1"> GetPageParameter</span><span style="color:#24292E">(</span><span style="color:#032F62">"pump"</span><span style="color:#24292E">, </span><span style="color:#032F62">""</span><span style="color:#24292E">);</span></span>
<span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> incomingPumpValid </span><span style="color:#D73A49">=</span><span style="color:#24292E"> incomingPump </span><span style="color:#D73A49">===</span><span style="color:#032F62"> "PUMP01"</span><span style="color:#D73A49"> ||</span><span style="color:#24292E"> incomingPump </span><span style="color:#D73A49">===</span><span style="color:#032F62"> "PUMP02"</span><span style="color:#24292E">;</span></span>
<span class="line"><span style="color:#D73A49">var</span><span style="color:#24292E"> incomingMessage </span><span style="color:#D73A49">=</span><span style="color:#24292E"> incomingPumpValid</span></span>
<span class="line"><span style="color:#D73A49"> ?</span><span style="color:#032F62"> "Current: "</span><span style="color:#D73A49"> +</span><span style="color:#24292E"> incomingPump</span></span>
<span class="line"><span style="color:#D73A49"> :</span><span style="color:#032F62"> "Invalid pump parameter. Cancel and reopen."</span><span style="color:#24292E">;</span></span></code></pre></div>
<p class="doc-step-result"><strong>Expected result</strong> The first visit displays Current: PUMP01. After choosing PUMP02, reopening must display Current: PUMP02.</p>
</article>
<article class="doc-card">
<h3 id="recipe-popup-selection-item-5">5. Return a selection or cancel</h3>
<p>Each row belongs to a different button’s Click Script. The result wrapper explicitly identifies the value returned to the source.</p>
<p class="doc-table-hint">Scroll horizontally to view the full table</p>
<div class="doc-table-scroll" role="region" aria-label="5. Return a selection or cancel" tabindex="0"><table class="doc-reference-table">
<thead><tr><th scope="col">Button</th><th scope="col">Click Script</th></tr></thead><tbody>
<tr><th scope="row">Choose PUMP01</th><td>if (!incomingPumpValid) return;
return HQ.popup.close({ result: "PUMP01" });</td></tr>
<tr><th scope="row">Choose PUMP02</th><td>if (!incomingPumpValid) return;
return HQ.popup.close({ result: "PUMP02" });</td></tr>
<tr><th scope="row">Cancel</th><td>return HQ.popup.close({ result: null });</td></tr>
</tbody></table></div>
<div class="manual-code" data-code-language="javascript"><div class="manual-code-toolbar"><span>Choose PUMP02 button → Click Script</span><span class="manual-code-tools"><small>JavaScript</small><button type="button" data-copy-code data-copied="Copied" data-failed="Select and copy the code" aria-label="Copy code: Choose PUMP02 button → Click Script">Copy code</button><span class="manual-code-status" role="status"></span></span></div><pre tabindex="0" class="docs-code-block shiki github-light" style="background-color:#fff;color:#24292e" tabindex="0"><code><span class="line"><span style="color:#D73A49">if</span><span style="color:#24292E"> (</span><span style="color:#D73A49">!</span><span style="color:#24292E">incomingPumpValid) </span><span style="color:#D73A49">return</span><span style="color:#24292E">;</span></span>
<span class="line"><span style="color:#D73A49">return</span><span style="color:#005CC5"> HQ</span><span style="color:#24292E">.popup.</span><span style="color:#6F42C1">close</span><span style="color:#24292E">({ result: </span><span style="color:#032F62">"PUMP02"</span><span style="color:#24292E"> });</span></span></code></pre></div>
<p class="doc-step-result"><strong>Expected result</strong> Choose PUMP02: the popup closes and the source changes to Selected: PUMP02. Cancel: it closes without changing the selection.</p>
</article>
<article class="doc-card">
<h3 id="recipe-popup-selection-item-6">6. Export and verify</h3>
<p>Save both slides, export through MX Design → Export → Export HTML, and verify overview in Mingcedar.</p>
<ol>
<li>Open from PUMP01 and choose PUMP02; confirm the source text updates.</li>
<li>Reopen and confirm the popup receives PUMP02. Cancel and verify the source keeps PUMP02.</li>
<li>Temporarily replace value: popupSelectedPump with value: "PUMP99" in the open code and export again. Confirm Invalid pump parameter appears, neither choice returns a result, and Cancel still closes the popup. Restore the original code.</li>
<li>To retarget Input, declare its possible Tags as in the Input lesson and update its target variable inside then. To filter Table, update its filter variable. Changing a page variable does not itself write a PLC.</li>
</ol>
<div class="doc-step-troubleshooting"><p><strong>If the result differs</strong></p><ul>
<li>Popup does not open: check Page Code, export scope and that both pages belong to the same package.</li>
<li>Source does not update: return the open Promise, update the source Page Script variables, and display them through Script Text rather than static text.</li>
<li>Only enable allowMultiple when separate concurrent instances are required; this exercise opens one picker at a time.</li>
</ul></div>
<ul class="doc-related-links">
<li><a href="/en/ppt/manual/recipe-page-parameter-input/">Next: switch the Input target</a></li>
<li><a href="/en/ppt/manual/recipe-parameterized-table/">Next: filter the table</a></li>
<li><a href="/en/ppt/manual/interaction-open-page-as-popup/">Popup fields and closing reference</a></li>
</ul>
</article>
</div>
</div>