- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 12:24 PM
Hi,
what is the best way to push information from a table to GitHub? I wish to send information and files from a table in ServiceNow to GitHub.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 12:37 PM
HI @Christoph Marku ,
I trust you are doing fine.
- Retrieve data from the ServiceNow table: You can use ServiceNow's GlideRecord API to query the table and retrieve the desired information. Here's an example code snippet in Javascript:
var table = 'your_table_name';
var gr = new GlideRecord(table);
gr.query(); // Add conditions if needed
while (gr.next()) {
var data = gr.getValue('column_name'); // Retrieve specific column data
// Process the data as per your requirements
// You can also retrieve multiple columns and create a JSON payload
}
Format the data: Depending on your requirements, you may need to format the data retrieved from ServiceNow into a suitable format for GitHub. This could be JSON, CSV, or any other format supported by GitHub's API.
Push data to GitHub: Use GitHub's API to create a new file or update an existing file with the formatted data. You'll need to authenticate with your GitHub account and have appropriate permissions for the repository. Here's an example code snippet using GitHub's REST API in Javascript:
var githubToken = 'your_github_token';
var repository = 'owner/repo'; // Replace with your repository details
var filePath = 'path/to/file.txt'; // Replace with the desired file path
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('PUT');
request.setRequestHeader('Authorization', 'Bearer ' + githubToken);
request.setEndpoint('https://api.github.com/repos/' + repository + '/contents/' + filePath);
var content = 'Your formatted data'; // Replace with the formatted data
var contentBase64 = GlideStringUtil.base64Encode(content);
var requestBody = {
"message": "Commit message",
"content": contentBase64
};
request.setRequestBody(JSON.stringify(requestBody));
var response = request.execute();
var responseBody = response.getBody();
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2024 09:55 AM
Hi @Christoph Marku, Unito has a no-code integration for ServiceNow that syncs records to issues in GitHub. It's fully customizable and you don't have to write script to configure it. If you can share a few more details about your use case, I can put together a demo for you. Otherwise, here's a step-by-step guide on how to sync Azure DevOps work items to records with 2-way updates. You can also find more details about Unito's ServiceNow integration here.