Auto Populate date and time field value from anothe table date time field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
@Krishna101, create a "After" Business Rule on meeting table. Select "Insert" "update" as per your use case and set the condition as shown below.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Vikas,
i have created after business Rule in meeting table, but its not working
Thanks
Krishna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@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.
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);
Here's the end result after updating the CAB Meeting record how it updated the Change Request.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/