- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 04:43 AM
HI All
I have a requirement in change module. There are two fields in change request and CTASK table that is "Planned start date" and "Planned end date". So the requirement is whenever any CTASK created, "Planned start date" and "Planned end date" should be auto fill from the change request form. For this I have written two onLoad client script and two script include. Issue is whenever I am opening a new Ctask or existing Ctask all the time it is showing a warning message "Task end date should be in the change window" and end date field is become blank. Can some one please help me where my script is going wrong or what should I do to correct script so that it will work fine. Below is the code.
Thanks in advanced
Script include: populatesupportGroup3
var populatesupportGroup3 = Class.create();
populatesupportGroup3.prototype = Object.extendsObject(AbstractAjaxProcessor, {
groupPopulation: function(){
var sysID = this.getParameter('sysparm_cr_sysid');
var crGrp = new GlideRecord('change_request');
crGrp.get(sysID);
return crGrp.end_date;
},
type: 'populatesupportGroup3'
});
Client script: Copy Planned end date from Chg request
function onLoad() {
//Type appropriate comment here, and begin script below
var group = new GlideAjax('populatesupportGroup3');
group.addParam('sysparm_name', 'groupPopulation');
group.addParam('sysparm_cr_sysid', g_form.getValue('change_request'));
group.getXML(result);
function result(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('planned_end_date', answer);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 11:50 PM - edited 05-03-2023 11:51 PM
So the 5 hour difference is causing the issue? That could be a localization issue as the time value held in the field is on another timezone and you're setting it to the field in your timezone.
In your script include try changing it like this:
var populatesupportGroup3 = Class.create();
populatesupportGroup3.prototype = Object.extendsObject(AbstractAjaxProcessor, {
groupPopulation: function(){
var sysID = this.getParameter('sysparm_cr_sysid');
var crGrp = new GlideRecord('change_request');
crGrp.get(sysID);
var gd = new GlideDateTime();
gd.setValue(crGrp.end_date);
return gd.getDisplayValue();
},
type: 'populatesupportGroup3'
});
Now you'd basically return the DisplayValue of the date field which should now be +-5hours different from the previous value.
Edit:
Changed GlideDate to GlideDateTime
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 05:01 AM
Check your client scripts for any where script contains alert(
There's probably a check that's preventing you from scheduling anything outside of the change window and you'd need to first check the logic in there and decide if you're doing something wrong or if the logic is incorrect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 05:29 AM
Hi
If you see the there is no alert message in this client script. May be oob client is validating and restricting it. But the problem is even if end time we are providing within the change window still that error message is appearing. Could you please provide any script which will copy planned start date and planned end date from the change request table and store in the change_task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 10:35 PM
Since the error is happening on client side, you could just create a before insert BR which copies the values to the task.
For example the script could be
current.planned_end_date = current.change_request.end_date;
However this means that the user would be confused about the fields if they're visible on the form when creating the task. There might also be a BR which checks for the date and could potentially prevent submit with a similar alert, so it might not be a complete solution.
But do check the other client scripts for the alert. You also want to make sure that there's no error in any of those.
It's rather easy to check since you can just filter by "script contains alert(" or "script contains Task end date should be in the change window" and you should get some result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 08:44 PM
Hi Prasnajeet,
I checked your script in my PD instance and it is working as expected and not getting any validation message for me.
I believe in your instance, some validation script is written, and it is causing an issue.
- Thanks
- Kailas