- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2015 01:30 AM
Hi,
I am facing issue with the below business rule. Please assist me.
This is my code in demo instance:-
function ondisplay(current, g_scratchpad){
var ou= new glideRecord('u_test');
ou.addQuery();
ou.query();
while(ou.next()){
current.u_organization = ou.u_organization;
current.update();
}
}
My requirement is populating a field based on value of another table. Let me explain u clearly:- I have created a new custom table called "test" which contains following fields (Name, Email, Organization) and we have base table called "Users". Both the tables contains the user information, Now I want to populate Organization field of User table based on Test table. So I have written the above business rule, it is populating the organization field but the issue is it is fetching the value of last record of Test table.
I know that I am missing something in the above code, I have to include one more line comparing the records of both the tables (I mean I have to take Email field as Reference and compare values of both the tables, if match is found organization field of User table should get populated with the organization field value of Test table).
Please assist me.......
Thanks in Advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2015 03:12 AM
var ou= new GlideRecord('u_test');
ou.query();
while(ou.next())
{
var getUserData = new GlideRecord('sys_user');
getUserData.addQuery('email',ou.u_email);
getUserData.query();
if(getUserData.next())
{
ou.u_organization = getUserData.u_organization;
ou.update();
}
}
//change the field names as per your setup

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2015 01:52 AM
This code should not be in business rule. Remove it from it.
If it is a one time activity, you may either use background script or on-demand scheduled job.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2015 02:24 AM
Thanks for the Reply. I want this code to be run after every 4 hours. So I should use a Scheduled job right?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2015 02:26 AM
Yup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2015 02:55 AM
Thanks Kalaiarasan. It worked fine now.
Thank you very much..........

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2015 01:39 AM