Populate the value of the field depending on the created date of a configuration item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 05:14 AM
I've got a situation where I'm trying to populate a field called 'Legacy or New' depending on the value of the created date:
I'm wanting to do a comparison of the value of the Test create date field against the value of a system property:
The outcome that I'm wating to achieve is that if the created date of the selected business application is older than 01-09-2024, then the 'Legacy or New' field should be populated to 'Legacy'. Otherwise, the 'Legacy or New' field should be populated to 'New'.
If somebody could let me know what I need to do, that would be great.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 07:58 AM
Hi Matthew,
You can do this with a Display or before Update Business Rule, if you want the field populated when a record is viewed or updated, or a Fix Script if you want to update all of the records. The BR would look similar to this:
(function executeRule(current, previous /*null when async*/) {
var newDate = gs.getProperty("lbg.AMANewApplicationDate");
if (current.date_field_name < newDate) {
current.string_field_name = 'Legacy';
} else {
current.string_field_name = 'New';
}
current.update(); //only use this line if When to run is Display or before Update
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 01:16 AM
@Brad Bowman It's on a catalogue item when it needs to be displayed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 08:46 AM
Hello @matthew_hughes ,
Assuming you wanted this to work on catalog item.....
1. Create "Legacy or New" variable as select Box. as follow.
2. Then Create a onchnage Client script on Create Date Variable .
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var createDate = g_form.getValue('test_create_date');
var ga = new GlideAjax('validateCreateDateUtils');
ga.addParam('sysparm_name', 'validateDate');
ga.addParam('sysparm_date', createDate);
ga.getXMLAnswer(processResponse);
function processResponse(reposnse) {
alert('response is ' + reposnse);
if (reposnse == 'true') {
g_form.setValue('legacy_or_new', 'legacy');
} else if (reposnse == 'false') {
g_form.setValue('legacy_or_new', 'new');
}
}
}
Create a client callable script include:
var validateCreateDateUtils = Class.create();
validateCreateDateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateDate: function() {
var CreateDate = this.getParameter('sysparm_date');
var DateTime = new GlideDateTime(CreateDate);
var propDate = new GlideDateTime(gs.getProperty('applicationDatecheck')); ///get your sys_property Value
if (CreateDate < propDate) {
return true;
} else {
return false;
}
},
type: 'validateCreateDateUtils'
});
Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.
Regards,
Siddhesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 01:15 AM
@Siddhesh Gawade When I try and select a business application, I get the error message of 'There is a JavaScript error in your browser console' and the Legacy or New system stays at None