Category:
Updated on: August 30, 2025  |  0

Client Script Patterns 3 - Catalog Client Scripts

🔧 Client Script Patterns:

Examples & Scenarios

 

5) Catalog Client Scripts (scoped to Catalog Items)

5.1 Real-time pricing math

 
function onChange(control, oldValue, newValue) { var qty = parseInt(g_form.getValue('quantity') || 1, 10); var unit = parseFloat(g_form.getValue('unit_price') || 0); g_form.setValue('total_price', (qty * unit).toFixed(2)); }

5.2 Show extra fields for “Laptop” model

 
function onChange(control, oldValue, newValue) { var show = (newValue == 'laptop'); g_form.setDisplay('memory_size', show); g_form.setMandatory('memory_size', show); g_form.setDisplay('disk_type', show); }

5.3 Validate email format on variable

 
function onChange(control, oldValue, newValue) { if (!newValue) return; var re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!re.test(newValue)) { g_form.showFieldMsg(control, 'Enter a valid email address.', 'error'); g_form.setValue(control, ''); } }

5.4 Block submit if attachment missing (Catalog)

 
function onSubmit() { if (!g_form.hasAttachments()) { g_form.addErrorMessage('Please attach supporting documentation.'); return false; } return true; }
 

6) Mobile & Portal nuances

6.1 Detecting Mobile (avoid heavy logic)

 
function onLoad() { if (g_user_agent && g_user_agent.isMobile()) { g_form.setDisplay('long_text', false); } }

6.2 Service Portal widget interactions

  • Prefer Client Script + spModal/nowModal patterns in widgets.

  • For classic forms rendered in Portal, most g_form APIs work; avoid DOM hacks.

 
 

Comments

No comments yet.


Log in to post a comment