Auto Populate date and time field value from anothe table date time field value

Krishna101
Tera Contributor

Hi Everyone,
Good Day!
I have field as near_meeting_date (Field type as Date/Time) in change request table and having another field
as meeting_start_date (Field type as Date/Time) in meeting table, I want to auto populate nearest date value of meeting_start_date  to 'near_meeting_date' in change request form. Could you please give suggest how we can get this requirement.
Thanks,
Krishna

20 REPLIES 20

VikMach
Mega Sage

@Krishna101, create a "After" Business Rule on meeting table. Select "Insert" "update" as per your use case and set the condition as shown below.

VikMach_0-1755625085335.png


And add the following script. Assuming you have one reference to change request in your meeting table.
Change variable "change_request_number" to your actual change request variable name in meeting table.
So, whenever the meeting table records are inserted or updated it will carry the same field value to change request record. (I don't know if you are updating "near_meeting_date" on insert, I just assumed)

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

    // Add your code here

    var changeGR = new GlideRecord('change_request');
    if (changeGR.get(current.change_request_number)) {
        changeGR.u_near_meeting_date = current.u_meeting_start_date;
        changeGR.update();
    }

})(current, previous);

 
Hope this helps.
Let me know if it works.

Regards,
Vikas K

Hi Vikas,
i have created after business Rule in meeting table, but its not working

Thanks
Krishna

@Krishna101, It is not working because you don't have any reference to Change Request record in CAB Meeting table. See snip below. You're querying something that is not even there out of the box. I am not sure if you have a custom field that you have created on your own in CAB Meeting table to reference Change Request. Have you??? Answer this question first.

VikMach_0-1755691441434.png



If you have not created then well and good because here's what you need to do. You should be querying "cab_agenda_meeting" which has the reference to both CAB Meeting and its respective Change Request and the correct "After" Business Rule will look like this, which should be created on "cab_meeting" table.
Follow this step and it should work. I tried in my PDI and it was successful.

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

	// Add your code here 
    var grAgenda = new GlideRecord('cab_agenda_item');
    grAgenda.addQuery('cab_meeting', current.sys_id);
    grAgenda.query();

    while (grAgenda.next()) {
        var changeRequest = new GlideRecord('change_request');
        if (changeRequest.get(grAgenda.task)) {
            changeRequest.cab_date_time = current.start;
            changeRequest.update();
        }
    }

})(current, previous);

 

VikMach_1-1755693846634.png



Here's the end result after updating the CAB Meeting record how it updated the Change Request.

VikMach_2-1755694050219.png

 

 

Note - By the way it looks like latest release has CAB Date/Time field Out of the Box to capture the Date Time. Explore and correct this if needed. Just indicating...

Cheers!
Hope this helps.
Let me know if any issue.

Regards,
Vikas K

kaushal_snow
Mega Sage

Hi @Krishna101 ,

 

Use a Before Business Rule on change request table........


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

var meetGr = new GlideRecord('meeting');
meetGr.addQuery('change_request', current.sys_id);
meetGr.orderBy('meeting_start_date');
meetGr.query();

if (meetGr.next()) {
current.near_meeting_date = meetGr.meeting_start_date;
}
})(current, previous);

 

There are alternate ways as well, let me know if this works...

 

If you found my response helpful, please mark it as ā€˜Accept as Solution’ and ā€˜Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/