- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2025 05:38 AM
Newbie to Scripting here.
I want to use the SN OOTB "Revert to New" UI Action for Change. However, the 255 characters allowed in Condition line is not enough. So I am trying put all my conditions into a Script Include.
I think all I need returned "from" the script is a true or false?
I need help writing this Script Include. Below is my feeble and failed attempt to write the script.
Basically I want to check cur user to see if they are member of group with the listed sysid, then check the change types and change states and if they match any of the AND/OR conditions, return True. Else, false
Help is most definitely appreciated
Stacy Len
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2025 05:58 AM
use this script include
Then call it like this in UI action condition
new ConditionUtils().checkMyCondition(current)
var ConditionUtils = Class.create();
ConditionUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkMyCondition: function(current) {
if ((current.type == global.ChangeRequest.EMERGENCY && new global.ChangeRequest(current).isAuthorize()) || (current.type == global.ChangeRequest.NORMAL && new global.ChangeRequest(current).isAssess()) && gs.getUser().isMemberOf('9d385017c611428711d22104ce95c371') && (current.type == ChangeRequest.EMERGENCY && new ChangeRequest(current).isAuthorize()) || (current.type == ChangeRequest.NORMAL && new ChangeRequest(current).isAssess()) || (current.type == changeRequest.NORMAL && new ChangeRequest(current).isAuthorize()))
return true;
else
return false;
},
type: 'ConditionUtils'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2025 07:38 AM
that UI action is server side so you will have to make it client side and use gsftSubmit()
I highlighted the changed below
1) you need to set action name
2) set Client = true
3) set Onclick = function name I gave
function revertToNew() {
var confirm = confirm("Are you sure you want to revert this change to New?");
if (confirm.toString() == 'true')
gsftSubmit(null, g_form.getFormElement(), "revert_to_new_1");
}
if (typeof window == 'undefined')
runServerSideCode();
function runServerSideCode() {
var changeRequest = new ChangeRequest(current);
if (!changeRequest.revertToNew())
gs.addErrorMessage(gs.getMessage('State Model for {0} changes does not allow reverting change from {1} state', [changeRequest.getValue('type'), changeRequest.getDisplayValue('state')]));
action.setRedirectURL(current);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2025 10:11 AM
AnKur, one followup question if I man: You now have my conditiones in the condition field in the new UI Action. However, for all my conditions, the 255 char limit on that field will not suffice. How to get around that problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
if the 255 char limit exceeds then put that in script include function and call it from UI action condition.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader