- 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-02-2015 01:38 AM
You need to specify which record you are looking for in
ou.addQuery();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2015 02:11 AM
Hi Kalaiarasan,
Thanks for the reply. I am new to scripting world! pls help me in achieving this.
I want all the records to get updated with the values of Test table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2015 02:17 AM
All the record of the table to be updated with what value ?
Comment this line if you want all the records
//ou.addQuery();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2015 02:48 AM
I want Organization field of User table to be populated with corresponding (Organization) field value of Test table.
For example:- There are 10 users in both the tables, when the Email field of both the tables matches the organization field of User table should populate with the organization field value of Test table.