How to fetch(script) repository id and repository name from source data field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 10:54 AM
Hi,
How I can fetch and populate Repository ID and Repository Name in two different fields(Repositry ID, Repository Name).
Kindly help, thanks in advance.
Regards,
Juganta Kishore Nayak

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 11:31 AM
Hi Jugant,
Check for article by Ashutosh that has all possible cases. Try checking and should help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 12:45 AM - edited 09-22-2023 12:47 AM
Dear Jugantanayak,
@jugantanayak , hope you're doing great!
[Using a business rule]:
You can create a business rule that will fetch the Repository ID and Repository Name from the Source Control Management (SCM) system and populate the corresponding fields on the record.
[For Creating Business Rule]:
- 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.
- Click the Save button.
[BUSINESS RULE]:
The following is an example of a business rule that you can use to fetch and populate the Repository ID and Repository Name fields:
// Business rule
function onAfter(current, previous) {
// Get the Repository ID and Repository Name from the SCM system.
var repositoryRecord = GlideRecord('source_control_repository');
repositoryRecord.get('sys_id', current.source_control_repository);
// Populate the Repository ID and Repository Name fields.
current.repository_id = repositoryRecord.getValue('sys_id');
current.repository_name = repositoryRecord.getValue('name');
// Update the record.
current.update();
}
[SCRIPT]:
You can also create a script that will fetch the Repository ID and Repository Name from the SCM system and populate the corresponding fields on the record.
To create a script:
- 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 repositoryRecord = GlideRecord('source_control_repository');
repositoryRecord.get('sys_id', current.source_control_repository);
// Populate the Repository ID and Repository Name fields.
current.repository_id = repositoryRecord.getValue('sys_id');
current.repository_name = repositoryRecord.getValue('name');
// Update the record.
current.update();
6. Click the Save button.
Once you have created the business rule or script, you can attach it to the appropriate table and field.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 08:43 AM
Hi ,
Can I achieve it through array script?
Regards,
Juganta