How to populate the user name through sys_id

vinod6
Tera Contributor

I have a sys_id . by using this sys_id i have populate user name u_requested _for field

 

Any one could you please help me

3 REPLIES 3

Vishal Birajdar
Giga Sage

Hi @vinod6 

 

Is it on Catalog item..??

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

AndersBGS
Tera Patron
Tera Patron

Hi @vinod6 ,

 

Please elaborate some more in relation to if it is a catalog item, form, workspace and what type op field you have created etc. 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Revanth Karra
Tera Expert

Dear Vinod,

 

Hope you're doing great!

 

@vinod6 , Got it! Try these methods 

 

METHOD 1: [USING BUSINESS RULE]

 

To populate the u_requested_for field using a sys_id:

You can create a business rule that will populate the u_requested_for field when the record is created or updated. To do this, follow these steps:

  1. Navigate to System Administration > Business Rules.
  2. Click the New button.
  3. Enter a name and description for the business rule.
  4. Select the Table that you want to apply the business rule to.
  5. Select the Condition that you want to use to trigger the business rule.
  6. Select the Action that you want to perform when the business rule is triggered. In this case, you would select the Set Field Value action and set the u_requested_for field to the sys_id of the user.
  7. Click the Save button.

 

METHOD 2: [USING SCRIPT]

 

You can create a script that will populate the u_requested_for field. To do this, follow these steps:

  1. Navigate to System Administration > Scripts.
  2. Click the New button.
  3. Enter a name and description for the script.
  4. Select the Script Type that you want to use. In this case, you would select the Business Rule script type.
  5. Add the following code to the Script field:

 

 

 

var userRecord = GlideRecord('sys_user');
userRecord.get('sys_id', 'sys_id_of_user');
var userName = userRecord.getValue('name');

var record = GlideRecord('table_name');
record.get('sys_id', 'sys_id_of_record');
record.setValue('u_requested_for', userName);
record.update();

 

 

 

 

NOTE:

  • Replace sys_id_of_user with the sys_id of the user that you want to populate the u_requested_for field with.
  • Replace sys_id_of_record with the sys_id of the record that you want to populate the u_requested_for field for.

Once you have created the business rule or script, you can use it to populate the u_requested_for field. For example, if you created a business rule, the business rule would be triggered when the record is created or updated. If you created a script, you can run the script manually or schedule it to run on a regular basis.

 

 

Kindly, please mark my solution as Helpful/Correct, if applicable. If I could help you with your Query then, please hit the Thumb Icon and mark as Correct!!!

 

Thanks & Regards, 

Revanth. K

Product Test Automation Engineer