- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2024 05:47 AM
Hi guys, I am trying to copy one date field from sys_user table to sc_req_item table and to achieve this I created display Business rule with g_scratchpad with a couple properties and use them in the onLoad client script but it's not working can someone please help me.
I am getting output as undefined in date field on RITM form.
Many thanks.
Display BR:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2024 09:48 AM
Hi @abhaysingh98 ,
Please try the below:
Display Business rule on [sc_req_item]
(function executeRule(current, previous /*null when async*/ ) {
var grUser = new GlideRecord('sys_user');
if (grUser.get(current.requested_for)) {
g_scratchpad.getDateVal = current.requested_for.u_account_expiry_date;
}
})(current, previous);
Onchange Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.setValue("u_due_date_2", g_scratchpad.getDateVal);
}
Please hit like and mark my response as correct if that helps.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2024 06:27 AM
Hi
current.sys_user
in your display BR makes no sense and furthermore you did not explain from which user you want to pull the data. From the currently logged-in user? If so, set the default value on the dictionary record of the related field u_account_expiry_date. For some inspiration, please refer to https://blog.snowycode.com/post/how-to-auto-populate-the-current-user-in-servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2024 06:55 AM - edited 06-08-2024 06:56 AM
Hi maik,
I want to pull the data for requested for user not for logged in user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2024 09:48 AM
Hi @abhaysingh98 ,
Please try the below:
Display Business rule on [sc_req_item]
(function executeRule(current, previous /*null when async*/ ) {
var grUser = new GlideRecord('sys_user');
if (grUser.get(current.requested_for)) {
g_scratchpad.getDateVal = current.requested_for.u_account_expiry_date;
}
})(current, previous);
Onchange Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.setValue("u_due_date_2", g_scratchpad.getDateVal);
}
Please hit like and mark my response as correct if that helps.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2024 10:37 AM
thank you very much!