Set Variables to Read Only on Caatlog Task
Readonly Variables on a Standard Form
A
while ago I helped to answer a forum posting for someone who was looking for a way to present catalog variables to an end-user on a Request Item grade only restrict the editing of those variables. At the time, I came up with a solution that worked, but that I actually wasn't happy with. I recently came beyond another forum posting where the poster wanted to practise something similar. The departure for the most recent poster was that the variables were to be shown on an Incident form (which had been generated past a record producer). There were some subtle differences in the manner variables were presented on the different forms that made my original script unusable for the incident form. So, I've had to revisit this topic to come up up with a better solution and I've decided to compile all of the different options for making variables read only on a regular form. These solutions tin exist used in a multifariousness of places, but will nigh often be practical to the Itemize Item, Catalog Task, Incident, or Change Asking tables. Enjoy!
Locking down variables past role without a script…
Its probably best to avert writing any script at all if you tin to lock downwards access to variables. Service-now allows you to add roles to any variable in the system for this purpose. If you want to lock downwardly variables without using a script, the solution can be found here. This solution is very simple but often doesn't give you lot the type of flexibility that you demand to restrict access to variables. It also requires you to gear up access to each and every variable in the system individually.
Locking downwardly variables via business rules…
Probably the simplest way of locking down variables on a standard form via script is to create a business organization rule that checks to see if the variables accept changed and then to arrest the submission of the chore record if they take changed. To exercise this, you lot but take to create a 'before' business rule on the table you lot desire to restrict the editing of variables. The business rule should have a condition of 'electric current.variable_pool.changes()'. Y'all can put whatsoever you want in the script field but it should include 'electric current.setAbortAction("true");'. If the user changes variable values and tries to submit the tape they would become an alert telling them that they are not allowed to change variables. Here's a sample…
Name: Abort on Variable Modify
Tabular array: Requested Item (or whatsoever tabular array you desire to restrict changes to)
When: Before
Update: True
Condition: current.variable_pool.changes()
Script:
gs.addInfoMessage ( 'You are not allowed to modify variable values on this record.' ) ;
current.setAbortAction ( truthful ) ;
action.setRedirectURL (electric current) ;
The other option is to only not show the variables at all and instead dump them into the work notes or comments fields. Here's a script I found on the forums that takes all of the variables for a given item and sends them to the piece of work notes field on that aforementioned item.
Name: Copy Variables to Work Notes
Table: Requested Item
When: Before
Insert: True
Script:
for (central in current.variables ) {
var v = current.variables [key] ;
wn += '\due north' + v.getGlideObject ( ).getQuestion ( ).getLabel ( ) + ': ' + v.getDisplayValue ( ) ;
}
current.work_notes = wn;
Locking down variables via client scripting…
Service-now actually provides a simple way to brand a variable on a standard task class read simply via client scripting. If you lot just need to disable one or two variables on a single item then this is probably the best scripting option. The solution is documented here.
Mostly nevertheless, if you are disabling variables at all, you are disabling them entirely or disabling them for a sure group of users. For that case, you could use a script like this ane to lock downwards all of the variables on a form. This script looks for the 'Variables' characterization on the variable formatter and disables the variables associated with information technology. Information technology is designed to work on any job tabular array in Service-now.
Proper noun: All Variables Readonly
Table: Incident, Change request, Request particular, Itemize task, wherever!
Blazon: onLoad
endeavour {
//Get the 'Variables' section
var ve = $( 'variable_map' ).upward ( 'tabular array' ) ;
//Disable all elements within with a course of 'cat_item_option'
ve.select ( '.cat_item_option' , '.slushselectmtm' , '.questionsetreference' , '.form-control' , '.checkbox' ).each ( function (elmt) {
elmt.disabled = truthful ;
} ) ;
//Remove any reference or calendar icons
ve.select ( 'img[src*=reference_list.gifx]' , 'img[src*=small_calendar.gifx]' ).each ( office (img) {
img.hide ( ) ;
} ) ;
//Hibernate listing collector icons
ve.select ( 'img[src*=arrow]' ).each ( function (img) {
img.upward ( 'table' ).hide ( ) ;
} ) ;
}
take hold of (e) { }
}
Share This Story, Choose Your Platform!
robinsonanytherver61.blogspot.com
Source: https://servicenowguru.com/scripting/business-rules-scripting/variables-form-readonly/
0 Response to "Set Variables to Read Only on Caatlog Task"
Post a Comment