Set custom radio button field in jira through rest api c# - c#

I'm trying to set the value of a custom radio button field that has 3 possible options: Yes, No or none. I'm using the Dapplo c# Jira SDK.
I've tried everything going from using "name" to "value" to "id" but nothing seems to work, I always get back "Could not find valid 'id' or 'value' in the Parent Option object".
Note that I want to set the field value by using the ID of the optionset value, not the textual value (like Yes or No) as that might change over time.
These are some of my attempts:
string jsonString = #"{""id"": ""11684""}";
var myJSON = JsonConvert.SerializeObject(jsonString);
issueToCreate.Fields.CustomFields.Add("customfield_12093", jsonString); //When I enter the 'jsonString' variable directly I get the same error.
does anyone have any idea? This seems much harder than it should be..

After trying about everything, the following finally worked:
var optionSetObject = new { id = "11681" };
issueToCreate.Fields.CustomFields.Add("customfield_12093", optionSetObject);
I thought the c# anonymous object wouldn't get serialized correctly, but apparently it does. Make sure the "id" value is a string though! If you enter it as an int, Jira won't recognize it for some reason.

You can try: (like use JavaScriptSerializer to serialise an anonymous object):
var optionSetObject = new { id = "11681" };
var serializer = new JavaScriptSerializer();
var output = serializer.Serialize(optionSetObject);
issueToCreate.Fields.CustomFields.Add("customfield_12093", output);

Related

How to Update KTA RunTimeField with an object?

I am trying to update an object (Generic List object) to RuntimeFiledCollection. When I try to update using the following code, I am getting always Serialization error :(
//My object which need to update set with the documentRuntimeField value
List<docInfo> docInfoList = new List<docInfo>
docInfo = new docInfo { ID = "11233", PageNumber = 1, text ="MyOwnText"};
docInfoList.Add(docInfo);
// Construct DOcument RuntimeFields Collection
var docRunTimeCollection = new CaptureDocumentService.RuntimeFieldCollection();
var docRunTimeField = new CaptureDocumentService.RuntimeField
{ Name = "FieldName", Value = docInfoList };
docRunTimeCollection.Add(docRunTimeField);
captureDocumentServiceClient.UpdateDocumentFieldValues(sessionId, null, validDocumentId, docRunTimeCollection);
I always get sterilization error as shown below. Can someone give me an example how to update document field values with an object. Any help ?
Error : There was an error while trying to serialize parameter http://www.kofax.com/agilityservices/sdk:runtimeFields.InnerException message was System.Collections.Generic.List
For RuntimeField class, you can see the the Value property is of type Object, but that is misleading, because it is not an arbitrary container. It takes the type that you defined for that field in your Extraction Group. But essentially that just means it will take a DateTime for a Date field or numeric types for a Number field, and anything else would be casted to string.
If you actually using a Table Field, then you cannot use the API to set the contents of the entire table. You would instead set the RuntimeField.TableRow and RuntimeField.TableColumn properties to use the API to set individual cells.

How to get GridLookup with complex name

I'm trying to get GridLookup selected value,
#Html.DevExpress().GridLookup(settingsGrid =>
{
settingsGrid.Name = "CommandeDetailEnCours.Compte";
settingsGrid.KeyFieldName = "Numero";
[...]
}).BindList(Model.ListeComptes).Bind(Model.CommandeDetailEnCours.Compte).GetHtml()
The question is: How I can get Value because in javascript
"CommandeDetailEnCours.Compte".GetGridView() [...]
not work ?
Use the client-side GetValue method in the following manner.
To retrieve the complex name on the client use the How to use the ClientInstanceName and Name properties when they contain special characters approach.
var lookupClientInstance = ASPxClientControl.GetControlCollection().GetByName("CommandeDetailEnCours.Compte");
var value = lookupClientInstance.GetValue();
alert(value);

How to store customfields from atlassian's Json Response e.g.(customfield_10020) which is coming dynamic everytime in c#

Here is the response I am getting from Api which is dynamic as shown in the picture. I got the value in customfield_10011 key. In the other object down I am getting value in customfield_10014 key. Now how should I loop it and save data in c#?
I had a similar problem with Jira API.
If you are 100% sure that those custom properties will not change then for sure go the dynamic route.
I have been integrating with multiple Jira instances and they had different custom fields for the same property, so a more fluent mapping is preferred, because it can be done dynamically from some configuration.
This can be achieved with a CustomContractResolver of JsonConvert.
Example:
return JsonConvert.DeserializeObject<JiraIssuePayload>(str, new JsonSerializerSettings()
{
ContractResolver = new CustomContractResolver(new Dictionary<string, string>
{
{"EpicName", "customfield_10011" },
{"Epic", "customfield_10012" }, // these could come from some configuration object
});
}
What is done here is that you tell JsonConvert to deserialize customfield_10011 to the property EpicName of your type (and Epic for the other one).
Using Json.Net it is simple enough to serialize it to Dynamic.
dynamic myDynamicJson = JsonConvert.DeserializeObject("{ 'environment': null, 'customfield_10027': "Multi Sensor Updated" }");
string customfield10027 = myDynamicJson.customfield_10027;
Edit
To get the field name from config I would rather go for the custom resolver method. But in case you can't:
dynamic myDynamicJson = JsonConvert.DeserializeObject("{ 'environment': null, 'customfield_10027': 'Multi Sensor Updated' }");
string myFieldNameFromConfig = "customfield_100273";
string result = myDynamicJson[myFieldNameFromConfig];

Handling nonexistant JSON tokens in JSON.Net how to return default instead of throwin exception

I have a problem, under http://www.pathofexile.com/api/public-stash-tabs link there is a huge API that returns a JSON string. Many of fields in this JSON are optional, that means they only appear if there is value present.
So theoretical "Item1" can have "abyssJewel" property but
"item2" doesnt have to have "abyssJewel" property
When i try to query this JSON with JSON.Linq like this
AbyssJewel = (bool)item["abyssJewel"];
in the case of Item1 everything is good and it returns proper value
but in case of Item2 i get exception "InvalidOperationException, Cannot access child value on Newtonsoft.Json.Linq.JProperty"
I understand its because for Item2 no abyssJewel property in JSON exists so it throws exception.
My question is this, how can i handle it so that instead of throwing exception it would return a default or null value for this particular field?
I have tried playing with Activator but couldnt make anything working on my own. Any tips?
im instantiating it like this:
apiPages.Add(new Page
{
Next_Change_Id = (string)jsonObject["next_change_id"],
Stashes = jsonObject["stashes"].Select(stash => new Stash
{
AccountName = (string)stash["accountName"],
StashName = (string)stash["stash"],
StashType = (string)stash["stashType"],
Public = (bool)stash["public"],
LastCharacterName = (string)stash["lastCharacterName"],
UniqueId = (string)stash["id"],
Items = stash.Select(item => new Item
{
AbyssJewel = (bool)item["abyssJewel"],
...tl;dr...
Instead of casting directly you should try to use the TryParse() method from the Boolean class, if something goes wrong it must return false. See here
Hope it will fix your problem.

How to select nested attribute in scan in DynamoDB?

I realize this is answered in the documentation (basically, "use the dot syntax"), but I'm still missing something. I'm using the .NET SDK and need to be able to select just a few attributes from a scan, one of which is a boolean inside a Map attribute. Note that I'm not trying to filter the results. I want all of the items, but I only want some of the attributes returned to me.
var config = new ScanOperationConfig
{
AttributesToGet = new List<string> { "foo.bar" },
Select = SelectValues.SpecificAttributes
};
var search = Table.Scan(config);
var documents = await search.GetRemainingAsync();
This code gets me the items I expect, but it's missing the "foo.bar" attribute. I know I can select the entire foo object, but I'm trying to minimize the amount of data handed back. I don't want the other attributes inside the foo object.
The relevant attribute of the item has the following JSON format:
{
"foo": {
"bar": true
}
}
I checked spelling, case sensitivity, etc. to no avail. Any idea what's wrong?
Instead of using Table.Scan, use the AmazonDynamoDBClient and you get more options.
The Client's ScanAsync method takes a ScanRequest which has a ProjectionExpression string. This is not present on the ScanOperationConfig class and that was the source of confusion.
Use the ProjectionExpression like so:
var scanRequest = new ScanRequest(Table.TableName)
{
ProjectionExpression = "foo.bar"
};
According to the documentation on ProjectionExpression:
ProjectionExpression replaces the legacy AttributesToGet parameter.
I didn't realize AttributesToGet was legacy until finally looking at the client for a totally unrelated problem and happened to find my answer to this problem.

Categories

Resources