- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2016 02:27 AM
Hi All,
We have an issue where people raising changes are able to alter the Planned start / end times aftert the change has been Scheduled. the change team have asked if there is a way to stop this occuring.
I'm trying to build a Client script that will lock the fields when the state changes to 'Scheduled' for everyone except the Change team.
I've created a new role called change_unlock for this purpose which i will give to the members of the change team.
Worth mentioning that I'm a total scripting novice with very basic Javascript skills
My script currently looks like this, but doesn't seem to do anything at all....
function onLoad()
{
var rqdrole = g_user.hasRole('change_unlock');
var state = g_form.getValue('State');
}
if (state == 'Scheduled' + (rqdrole)){
g_form.setReadonly('start_date',false);
g_form.setReadonly('end_date',false);
}
else {
if (state == 'Scheduled')
g_form.setReadonly('start_date',true);
g_form.setReadonly('end_date',true);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2016 02:48 AM
Hi Paul,
I have edited little bit. Below is the code.
function onLoad()
{
var = g_user.hasRole('change_unlock');
var state = g_form.getValue('state');
if(!rqdrole){
if (state != 'DontForegetTOReplaceThisWithChoiceValue' ){ // You can find the choice value of schedule Label by right clicking on the state field in the form and show choice list
g_form.setReadonly('start_date',false);
g_form.setReadonly('end_date',false);
}
else {
g_form.setReadonly('start_date',true);
g_form.setReadonly('end_date',true);
}
}
}
Hope this helps
Srini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2016 02:36 AM
Hi Paul,
A slight modification in your script
function onLoad()
{
if(isLoading) return false;
var rqdrole = g_user.hasRole('change_unlock');
var state = g_form.getValue('State');
}
if (state == 'Scheduled' && rqdrole ){
g_form.setMandatory('start_date',false); // This makes the field non mandatory
g_form.setReadonly('start_date',false);
g_form.setMandatory('end_date',false); // This makes the field non mandatory
g_form.setReadonly('end_date',false);
}
else {
if (state == 'Scheduled')
g_form.setReadonly('start_date',true);
g_form.setReadonly('end_date',true);
}
Hope this works
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2016 02:44 AM
Hi Ketan,
Thanks for this, however I've just tried it by impersonating a user without the role and the fields are still editable...
Cheers
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2016 02:47 AM
Hi,
Gottcha : setReadonly function is setReadOnly
Hope that's the culprit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2016 02:48 AM
Hi Paul,
I have edited little bit. Below is the code.
function onLoad()
{
var = g_user.hasRole('change_unlock');
var state = g_form.getValue('state');
if(!rqdrole){
if (state != 'DontForegetTOReplaceThisWithChoiceValue' ){ // You can find the choice value of schedule Label by right clicking on the state field in the form and show choice list
g_form.setReadonly('start_date',false);
g_form.setReadonly('end_date',false);
}
else {
g_form.setReadonly('start_date',true);
g_form.setReadonly('end_date',true);
}
}
}
Hope this helps
Srini