How to fetch(script) repository id and repository name from source data field?

jugantanayak
Tera Guru

Hi,

How I can fetch and populate Repository ID and Repository Name in two different fields(Repositry ID, Repository Name).

 

jugantanayak_0-1695318692794.png

Kindly help, thanks in advance.

 

Regards,

Juganta Kishore Nayak

3 REPLIES 3

Jaspal Singh
Mega Patron
Mega Patron

Hi Jugant,

Check for article by Ashutosh that has all possible cases. Try checking and should help.

Revanth Karra
Tera Expert

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]:

  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.
  7. 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:

  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 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

jugantanayak
Tera Guru

Hi ,

 

Can I achieve it through array script?

 

Regards,

Juganta