REST API Populate custom fields with data

In our workplace, we use SharePoint and JIRA as issue trackers. In SharePoint, we have a list called "Work Requests," which store issue information in SharePoint list items. Before, we have had to manually create JIRA stories from these Work Requests, but I have created a c# program that will automtically take this SharePoint data and create JIRA tasks. This is what my program is right now with my urls replaced with default values: 

using Atlassian.Jira;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace ConsoleApplication3
{
public class Jira_SP_API
{
public static void Main(string[] args)
{
Jira jira = Jira.CreateRestClient("JIRA url", "username", "password");

var context = new SharePoint.ITDataContext(
new Uri("SharePoint url"));
context.Credentials = System.Net.CredentialCache.DefaultCredentials;

var workrequests = from request in context.WorkRequests
where request.Id > 240
where request.RequestStatusValue != null
orderby request.Id
select new
{
request.Id,
request.Title,
request.RequestStatusValue,
request.PriorityValue,
request.RequestDate,
request.Requestor.Name,
request.BusinessApprover.FirstName,
request.BusinessApprover.LastName,
request.WorkAssignedTo,
request.FunctionalArea,
request.WorkRequestFormReadOnly
};

foreach (var request in workrequests)
{
try
{
var issue = jira.CreateIssue("TEST");
issue.Type = "Task";
/*issue["customfield_10044"] = request.Id;*/
issue.Priority = request.PriorityValue;
issue.Summary = request.Title;
issue["customfield_10045"] = request.WorkRequestFormReadOnly;
issue["customfield_10050"] = request.FunctionalArea;
issue["customfield_10047"] = request.Title;
issue["customfield_10048"] = request.Name;
issue["customfield_10049"] = request.FirstName + ' ' + request.LastName;
issue["customfield_10046"] = null;
issue["customfield_10051"] = null;
issue["customfield_10052"] = null;

issue.SaveChanges();
}
catch (Exception) { }

 

Console.WriteLine(request.Id);
Console.WriteLine(request.Title);
Console.WriteLine(request.RequestStatusValue);
Console.WriteLine(request.PriorityValue);
Console.WriteLine(request.RequestDate);
Console.WriteLine(request.Name);
Console.WriteLine(request.FirstName + ' ' + request.LastName);
Console.WriteLine(request.WorkAssignedTo);

}
Console.ReadKey();
}
}
}

 

Basically my issue is that my program will create tasks when I don't have the custom fields in my foreach statement, but as soon as I put them in, my program will no longer create tasks. Is my formatting wrong? Or are the custom fields not supposed to work this way? Thanks in advance.

2 answers

Tried this:

issue.CustomFields.AddById("customfield_10045", request.WorkRequestFormReadOnly); //Link to Work Request
issue.CustomFields.AddById("customfield_10050", request.FunctionalArea); //Functional Area
issue.CustomFields.AddById("customfield_10047", request.Title); //Title
issue.CustomFields.AddById("customfield_10048", request.Name); //Requestor
issue.CustomFields.AddById("customfield_10049", request.FirstName + ' ' + request.LastName); //Approver

 

Still doesn't create the issue in JIRA. But this creates an issue when I remove the custom fields:

var issue = jira.CreateIssue("TEST");
issue.Type = "Story";

issue.Priority = request.PriorityValue;
issue.Summary = request.Title;

issue.SaveChanges();

Trey,

Am looking for similar kind of solution. would love to hear if you were able to integrate between sharepoint and jira ? if so do you mind sharing how you implemented it. 

Thanks

0 vote
Warren Levy Community Champion Jan 11, 2018

Hi guys

This is what the JSON looks like when I create an issue with a custom field :

 "customfield_11100": {
"value": "Non Project"
},

 I hope this helps you

Hey Warren,

So you create your JSON from sharepoint and trying to create the issue in Jira ? Just trying to understand on the integration of sharepoint and jira

Warren Levy Community Champion Jan 11, 2018

No, I don't work with SharePoint. I was mainly answering the question about creating an issue with a custom field. 

In theory you should be able "get" Jira data into SharePoint and also create Jira issues from SharePoint, as long as you're able to work with the API (which should be possible). In fact my company is considering a project of doing exactly this, but the SharePoint developers will be involved, not me.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

361 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you