Assigning value to a field based on another table?

Nani6
Mega Guru

Hi,

I'm battling with this business rule and would appreciate your assistance. New to scripting world!

We have a requirement to assign value to a field based on another table. Let me explain you clearly........... We have 2 tables sys_user table (base table) and organization data (custom table), both contains the user information. Both the tables contains a field called organization unit (custom field), which is a reference to some "X" table. Now the task is we have to populate this field organization unit on sys_user table based on organization data table.

Thanks in advance.........

4 REPLIES 4

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

You can do it with a calculation script on the field from sys_user table.



Here is a thread that might give you some ideas:



Calculated field vs Client script to populate field based on other field values



Regards,


Sergiu


Hi Sergiu,


Thanks for reply. Here in my case I have to populate a field based on value of another table. So I think we have to use Business rule.


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

You can still use GlideRecord in calculated fields.



For example, on my own instance I created a field called "myField" in incident table and added a calculation like this (just an example, adapt to your requirements):



var gr = new GlideRecord('task');


gr.addActiveQuery();


gr.setLimit(1);


gr.query();


while(gr.next()){


current.myfield = gr.number;


}



After I added the new field on incident form, just looking at an incident I see the value is populated. The XML shows:



<myfield>CHGPHASE0030001</myfield>



So, you can use GlideRecord for this:



GlideRecord - ServiceNow Wiki



Regards,


Sergiu


Thanks Sergiu