- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 05:42 AM

var task = new GlideRecord('task_sla');
task.addQuery('active', false);
task.query();
while (task.next()) {
var task_sysid = task.task;
//gs.print(task_sysid);
var inc = new GlideRecord('incident')
//inc.addQuery('active', false)
inc.addQuery('sys_id', '=', task_sysid)
inc.query();
//
while (inc.next()) {
task.u_dia_fc = inc.u_dia_fc;
task.u_mes_fc = inc.u_mes_fc;
task.u_ano_fc = inc.u_ano_fc;
task.update();
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 08:41 AM
You need to replace 'gr' by 'current' if you are using this code in a business rule.
var gdt = new GlideDateTime(current.sys_created_on);
Also, you have wrongly assigned the values below -
date[0] = u_ano_ab;
date[1] = u_mes;
date[2] = u_dia;
Instead, you need to fetch the value for date, month and year as -
current.<yourFieldNameForYear> = date[0];
current.<yourFieldNameForMonth> = date[1];
current.<yourFieldNameForDate> = date[2];
For example, if u_dia should store the date so it will be -
current.u_dia = date[2];
Please mark my answer as correct or helpful if applicable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 06:02 AM
Hi,
The screenshot does not clearly define what is your expected output but I assume with the title that you need to fetch the date, month, and year from the Created Date. For that, you can try the below code:
var gdt = new GlideDateTime(gr.sys_created_on); //say sys_created_on is the column name
var date = gdt.getLocalDate();
//date variable will contain the only the date part of the date/time field
date =date.toString();
date = date.split("-");
date[0] will be the year
date[1] will be the month
date[2] will be the date
Please mark my answer as correct or helpful if applicable.
Thanks,
Aishwarya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 07:23 AM

I did according to what was informed in a business rule and it didn't work, according to what was informed
(function executeRule(current, previous /*null when async*/ ) {
var gdt = new GlideDateTime(gr.sys_created_on); //say sys_created_on is the column name
var date = gdt.getLocalDate();
//date variable will contain the only the date part of the date/time field
date = date.toString();
date = date.split("-");
date[0] = u_ano_ab;
date[1] = u_mes;
date[2] = u_dia;
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 08:41 AM
You need to replace 'gr' by 'current' if you are using this code in a business rule.
var gdt = new GlideDateTime(current.sys_created_on);
Also, you have wrongly assigned the values below -
date[0] = u_ano_ab;
date[1] = u_mes;
date[2] = u_dia;
Instead, you need to fetch the value for date, month and year as -
current.<yourFieldNameForYear> = date[0];
current.<yourFieldNameForMonth> = date[1];
current.<yourFieldNameForDate> = date[2];
For example, if u_dia should store the date so it will be -
current.u_dia = date[2];
Please mark my answer as correct or helpful if applicable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 08:51 AM
Hey,
Try these:
var dt = new GlideDateTime();
gs.info( dt.getDayOfMonth() +" "+ dt.getMonth() +" "+dt.getYear());
//Output :13 5 2022
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar