How to populate the user name through sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 09:12 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 09:19 PM
Hi @vinod6
Is it on Catalog item..??
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 10:41 PM
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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 11:23 PM - edited 09-21-2023 11:34 PM
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:
- Navigate to System Administration > Business Rules.
- Click the New button.
- Enter a name and description for the business rule.
- Select the Table that you want to apply the business rule to.
- Select the Condition that you want to use to trigger the business rule.
- 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.
- 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:
- Navigate to System Administration > Scripts.
- Click the New button.
- Enter a name and description for the script.
- Select the Script Type that you want to use. In this case, you would select the Business Rule script type.
- 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