Current date/time auto-populate

Riya17
Giga Contributor

My requirement is to auto-populate the 'sys_created_on' in another custom field 'start date' which will be read-only on the same form only for new records.  Please help me make it working.

I have a BR.

Table : User Entitlement

When to run: after

condition: start date is empty

var gDatetime = new GlideDateTime(current.sys_created_on);
if (sys_created_on==' ') {
current.u_start_date = gDatetime;
}

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi riyak,

 

Notice the screenshots below

 

find_real_file.png

 

find_real_file.png

 

find_real_file.png

 

In my dev instance, the BR works correctly.

View solution in original post

11 REPLIES 11

Yogi3
Kilo Guru

here is the script. Run BR on after insert and condition should be created is not empty

 

 

find_real_file.png

 

(function executeRule(current, previous /*null when async*/) {

// Add your code here
current.u_start_block_date = current.sys_created_on;
current.update();

 

})(current, previous);

 

Cody Smith _ Cl
Tera Guru

Hello Riyak,

I am not sure I understand your code fully. Its getting the GDT of the sys_created_on field, then checking if that field is blank, and if it is blank fill it with the GDT from the blank field? It seems like it would not work because the time would be blank.

If sys_created_on is already a time field, you could just set start date to the same thing.

 

current.u_start_date = current.sys_created_on;

Also, in your IF statement, you don't have sys_created_on set as anything. You would need current, but again if it is empty then gDatetime would also be empty. 

I gave 'current for sys_created_on in IF statement, still not working.

 

var gDatetime = new GlideDateTime(current.sys_created_on);
if (sys_created_on=='current ') {
current.u_start_date = gDatetime;
}

Community Alums
Not applicable

Hi riyak,

 

Yout don't have to script this. 

Only set the action as following:

find_real_file.png

If my answer helped you in any way, please then mark it as helpful.