Resolve Primary Key to value on a record

EB7
Giga Contributor

I have two tables in ServiceNow that has company information and Contact information.

Company table:

Company Key

Company name

Company Address

1

Example Company 1

123 Sample Drive, City, ST 12345

2

Example Company 2

124 Sample Drive, City, ST 12345

3

Example Company 3

125 Sample Drive, City, ST 12345

 

Contact/User Table:

Contact key

Name

Contact Address

Company Key

11

John Smith

Xyz address

2

12

Adam Abel

Abc address

3

13

Rice Rich

Cde address

1

14

Nick Jay

Fgh address

2

 

Question is, how can I have Company name returned on a Contact/User form instead of Company key?

I have Oracle DB administration background and this is approached differently as I have direct access to the DB, but not the case in ServiceNow. Any suggestions will greatly be appreciated.

 

Thanks,

EB

1 ACCEPTED SOLUTION

EB7
Giga Contributor

Thanks,

 

I'm still on the initial loading of the data into ServiceNow. At this point that field is empty and I want it to load automatically from the transform. 

I have solved this issue by adding this script to the transform map:

answer = (function transformEntry(source) {

var companyID = "";

// Get company record using manufacturer seq number
if(source.u_company_key){
var mfr = new GlideRecord("u_manufacturer");
mfr.addQuery("u_company_key", source.u_company_key);
mfr.query();
if(mfr.next()){
companyID = mfr.getValue('u_company_name');
}
}

return companyID;

})(source);

View solution in original post

30 REPLIES 30

Let's say you have a reference to sys_user on Contact table and you pick one of the users, then we can populate the company of the user selected to company on Contact table.

 

Example: sys_user table record John Smith, company is 'Example Company 2

So in your Contact table if you have a reference field called User. Once you select Jogn smith we can populate the Example Company2 value on company field

Is this what you are looking for ?

Then you need to create a user field of reference type and write a Onchange client script

 

EB7
Giga Contributor

Thanks,

 

I'm still on the initial loading of the data into ServiceNow. At this point that field is empty and I want it to load automatically from the transform. 

I have solved this issue by adding this script to the transform map:

answer = (function transformEntry(source) {

var companyID = "";

// Get company record using manufacturer seq number
if(source.u_company_key){
var mfr = new GlideRecord("u_manufacturer");
mfr.addQuery("u_company_key", source.u_company_key);
mfr.query();
if(mfr.next()){
companyID = mfr.getValue('u_company_name');
}
}

return companyID;

})(source);

EB7
Giga Contributor

Glad you got it working 🙂

EB7
Giga Contributor

Thanks for your help... It made a difference!