- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 02:25 AM
Hello,
I am currently working on a client script within change requests to achieve the following:
If all of these are true -
Request company value is NHS Lothian (sys id, ad0459981b7c0c100375ca217e4bcbb0)
State changes to Closed (value, 3)
Assignment group is not NHSL-SN-ChangeManagement (sys id, 35f1f914dbf00c50731381cc0b961980)
Then revert state to Review (value, 0) and alert user that change requests can only be closed by change management.
I've tried with both onSubmit and onChange scripts but can't seem to get it working, below is my current working example, which executes when the state field changes however I am unsure if this is the best option to use as it would run on every state change and not just at the Review>Closed state which is what I am looking for, any help would be much appreciated.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var state = g_form.getValue('state');
var assignmentGroup = g_form.getValue('assignment_group');
var company = g_form.getValue('company');
// alert ('State: ' + state + 'AG: ' + assignmentGroup + 'Company: ' + company);
if (company == 'ad0459981b7c0c100375ca217e4bcbb0' && state == '3' && assignmentGroup != '35f1f914dbf00c50731381cc0b961980') {
g_form.setValue('state', '0');
alert('Change requests can only be closed by NHSL-SN-ChangeManagement');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2024 05:41 AM
This was fixed by using a business rule:
(function executeRule(current, previous /*null when async*/) {
var nhsLothianCompanySysID = 'ad0459981b7c0c100375ca217e4bcbb0';
var changeManagementGroupSysID = '61808333dba8c45089618a5039961911';
// Check if the request company is NHS Lothian
if (current.company == nhsLothianCompanySysID) {
// Check if the state is being changed to Closed (value 3)
if (current.state == 3) {
// Check if the assignment group is not NHSL-SN-ChangeManagement
if (current.assignment_group != changeManagementGroupSysID) {
// Revert the state to Review
current.state = 0;
// Add an error message
gs.addErrorMessage('Change requests can only be closed by change management');
// Prevent the record from being saved in the current (closed) state
current.setAbortAction(true);
}
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 05:32 AM
@Wasdom_Kung Put an alert to show the
alert(assignmentGroup);
before the if and see what value it shows.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 05:50 AM
State: -4
AG: 35f1f914dbf00c50731381cc0b961980
Company: ad0459981b7c0c100375ca217e4bcbb0
These are the returned values, state can be ignored, as it pops up for every state change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2024 05:41 AM
This was fixed by using a business rule:
(function executeRule(current, previous /*null when async*/) {
var nhsLothianCompanySysID = 'ad0459981b7c0c100375ca217e4bcbb0';
var changeManagementGroupSysID = '61808333dba8c45089618a5039961911';
// Check if the request company is NHS Lothian
if (current.company == nhsLothianCompanySysID) {
// Check if the state is being changed to Closed (value 3)
if (current.state == 3) {
// Check if the assignment group is not NHSL-SN-ChangeManagement
if (current.assignment_group != changeManagementGroupSysID) {
// Revert the state to Review
current.state = 0;
// Add an error message
gs.addErrorMessage('Change requests can only be closed by change management');
// Prevent the record from being saved in the current (closed) state
current.setAbortAction(true);
}
}
}
})(current, previous);