- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 01:29 PM
Hi everyone
I need to make the fields of the list readonly, all except the current month, and I would like for example if we are in June, the month of May becomes readonly and the month of June will be possible to edit it how can I do it?
thank you all
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 03:03 PM
I'm not familiar with this particular list view - what are the field types of the months? Are you able to edit all of these fields now?
If they are editable now, you need an onCellEdit client script for each 'month' field. Each client script will call the same GlideAjax (script include) passing in the number of the month that represents that field. The script include will get the current month, compare it to this value passed in from the client, then return true or false, which the client script will use to determine if updates to that field can be saved. They will appear to be editable, but changes won't be saved. Your client scripts will look similar to this
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
var ajax = new GlideAjax('DateUtils'); //name of the script include
ajax.addParam('sysparm_name', 'getMonth'); //name of the function in the script include
ajax.addParam('sysparm_month', '5');
ajax.getXML(checkdate);
function checkdate(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'false'){
saveAndClose = false;
alert('Only the current month is editable'); //optional
}
callback(saveAndClose);
}
}
This is the one for the May column. The scripts for the other months are the same except for the sysparm_month value. Next create a script include with the same name used in the GlideAjax call in the client scripts, ensuring the Client callable box is checked. Your script will look similar to this
var DateUtils = Class.create();
DateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getMonth: function(){
var answer = 'false';
var month = this.getParameter('sysparm_month');
var nowDT = new GlideDateTime(gs.nowDateTime());
var nowMonth = nowDT.getMonthLocalTime();
if(nowMonth == month){
answer = 'true';
}
return answer;
},
type: 'DateUtils'
});
If you want to make the other, non-month fields read-only, you'll also need onCellEdit client scripts for each of those fields.
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = false;
callback(saveAndClose);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2020 03:03 PM
I'm not familiar with this particular list view - what are the field types of the months? Are you able to edit all of these fields now?
If they are editable now, you need an onCellEdit client script for each 'month' field. Each client script will call the same GlideAjax (script include) passing in the number of the month that represents that field. The script include will get the current month, compare it to this value passed in from the client, then return true or false, which the client script will use to determine if updates to that field can be saved. They will appear to be editable, but changes won't be saved. Your client scripts will look similar to this
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
var ajax = new GlideAjax('DateUtils'); //name of the script include
ajax.addParam('sysparm_name', 'getMonth'); //name of the function in the script include
ajax.addParam('sysparm_month', '5');
ajax.getXML(checkdate);
function checkdate(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'false'){
saveAndClose = false;
alert('Only the current month is editable'); //optional
}
callback(saveAndClose);
}
}
This is the one for the May column. The scripts for the other months are the same except for the sysparm_month value. Next create a script include with the same name used in the GlideAjax call in the client scripts, ensuring the Client callable box is checked. Your script will look similar to this
var DateUtils = Class.create();
DateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getMonth: function(){
var answer = 'false';
var month = this.getParameter('sysparm_month');
var nowDT = new GlideDateTime(gs.nowDateTime());
var nowMonth = nowDT.getMonthLocalTime();
if(nowMonth == month){
answer = 'true';
}
return answer;
},
type: 'DateUtils'
});
If you want to make the other, non-month fields read-only, you'll also need onCellEdit client scripts for each of those fields.
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = false;
callback(saveAndClose);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 12:18 AM
It work fine! thanks