Hey all - I did read through some other posts but didn't find what I was looking for as I had already done those steps of troubleshooting.
I am working on rescoping some of our work as our SOW was stood up quickly and before there was much in docs/support. We have a 23 action UI Policy that I was able to rewrite as a Client Script because that seemed like a cleaner option. That runs as expected in Legacy (eventually we will be shutting Legacy off so trying to also get ahead of any issues that doing that may cause). For the SOW I cannot get a very similar script to run nor can I recreate the UI Policy in Form/UI Builder for 23 actions - the limit is 14 (I also opened a Case for this). I haven't chosen a View as that doesn't have a drop down (also bizarre) so left it blank but have tried typing in sow, SOW, a and Service Operations Workspace with no luck. Here is the code and screenshots. I appreciate any ideas that I haven't mentioned trying already. Thank you.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === oldValue) return;
applyLockIfNeeded(newValue);
}
// shared helper for here and an onLoad()
function applyLockIfNeeded(stateVal) {
// Adjust if your instance uses different values
var RESTORED = '6'; // "Resolved/Restored"
var CLOSED = '7';
var shouldLock = (stateVal == RESTORED || stateVal == CLOSED);
// Only the fields you actually want to lock in these states
var fieldsToLock = [
// List of fields to make read-only
'state',
'opened_at',
'opened_by',
'closed_by',
'closed_at',
'company',
'caller_id',
'impact',
'urgency',
'location',
'number',
'cmdb_ci',
'escalation',
'assignment_group',
'assigned_to',
'short_description',
'priority',
'close_notes',
'closed_code',
'comments',
'knowledge',
'work_notes'
];
// If you need any to remain editable even when locked, put them here
var exceptions = [
'category'
];
// Diagnostics banner (remove when done)
g_form.addInfoMessage(
'[LockCheck ' + (source || 'n/a') + '] state=' + stateVal +
' (' + (stateLabel || '?') + '), lock=' + shouldLock
);
// Lock only if the control exists on the form (prevents silent no-ops)
for (var i = 0; i < fieldsToLock.length; i++) {
var f = fieldsToLock[i];
if (exceptions.indexOf(f) === -1) {
var ctrl = g_form.getControl(f);
if (ctrl) {
g_form.setReadOnly(f, shouldLock);
} else {
// Log missing control so you can correct field names quickly
console && console.warn && console.warn('[LockCheck] Control not on form:', f);
g_form.addInfoMessage('[LockCheck] Not on form: ' + f);
}
}
}
} catch (e) {
// Surface any JS error; otherwise Workspace swallows it and nothing runs
g_form.addErrorMessage('Locking script error: ' + e.message);
console && console.error && console.error('Locking script error', e);
}