How to restrict client script to make changes on the records created before a particular date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 01:15 AM
I have written one on change client script that actually works on field "caller" on incident if we change the caller then it will auto populate the appropriate CI on the bases of that, but we do not want this CI to be auto populated on the incident which has been created before 1st Aug 2023.
Below is the client scrupt
function onChange(control, oldValue, newValue, isLoading) {
//if (isLoading) {
// return;
//}
var created = g_form.getValue('sys_created_on');
if(created ) {
}
if (newValue == '') {
g_form.setVisible('cmdb_ci', true);
g_form.clearValue('cmdb_ci');
return;
}
var caller = g_form.getValue('caller_id');
var ga = new GlideAjax('Inc_ci');
ga.addParam('sysparm_name', "getCIList");
ga.addParam('sysparm_role', caller);
ga.getXMLAnswer(function(answer) {
//g_form.addInfoMessage('Answer '+answer);
if (answer != '' && answer != 'List') { // Ci available - only 1
g_form.setDisplay('cmdb_ci', true);
g_form.setValue('cmdb_ci', answer);
} else if (answer == 'List') { // Ci available - multiple
g_form.clearValue('cmdb_ci');
g_form.setVisible('cmdb_ci', true);
} else if (answer == '') { // Ci avaialble - No
g_form.clearValue('cmdb_ci');
}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 01:46 AM - edited 08-01-2023 01:48 AM
Hi @VIKAS MISHRA ,
Try this
var created = g_form.getValue('sys_created_on');
var cutoffDt = new Date('2023-08-01');
var createdDate = new Date(created);
if (createdDate < cutoffDt ) {
//don't populate the CI in this case
return;
}
else{
//go on with your logic to populate
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 02:17 AM
check the created date within script include itself by using filter condition on CI table
Did you update the script include function?
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-01-2023 05:46 AM
Hi ankur,
You are correct with the client script i am unable to achive the same .
Below is my script include, could youe please suggest here, how can i add the restriction so that it would not be applied to the records created before 1/aug/2023
var Inc_ci = Class.create();
Inc_ci.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCIList: function() {
var list = [];
var user_id = this.getParameter('sysparm_role');
var created = this.getParameter('sys_created');
//gs.log('JT:user is ' + user_id);
// var gr = new GlideDateTime();
// gs.log(gr);
// if(created > new GlideDateTime('07-27-2023 00:00:00')){
var ci = new GlideRecord('cmdb_ci_pc_hardware');
ci.addQuery('assigned_to', user_id);
ci.query();
if (ci.next()) {
if (ci.getRowCount() == 1) {
//gs.log('JT: Row count is ' + ci.getRowCount());
return ci.getValue('sys_id');
}
return "List";
}
return "";
// }
},
type: 'Inc_ci'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 05:58 AM
Is it always 1st August 2023 or the date will be dynamic?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader