500 error when querying workfront api Hours + parameterValues - c#

When calling WorkFront's API
https://preview.workfront.com/attask/api/v7.0/HOUR/search?fields=*,parameterValues
I get a 500 error. It works fine if I don't specify parameterValues. In comparison providing a bogus field returns:
https://preview.workfront.com/attask/api/v7.0/HOUR/search?&fields=*,garbageParam
{"error":{"class":"java.lang.IllegalArgumentException","message":"APIModel V7_0 does not support field garbageParam (Hour)"}}
I can't simply remove parameterValues because the url is generated by the code, and I didn't see a means of determining if a particular ObjCode will or won't crash if given parameterValues.
My code is supposed to dump the JSON into C# classes I have, so I need all the fields that are available. Unfortunately WorkFront crashing by being requested all the fields is throwing a wrench into the design.
Is there a way to get around the 500 error, or a way to detect if paramterValues should be provided or not?

I am not sure why you are getting a 500 Error rather then a more specific error but Hours do not contain custom data so parameterValues would not contain any data on the HOUR object. If you were to make the same Call on the TASK object it would work.

Related

MVC: Timeout issue

I'm trying to extract the results of a SQL server view in MVC. The view itself is relatively straightforward and UNIONs a couple of tables together - when run it takes around 2 seconds to return its rows. I've added the view to my model in MVC.
In my controller I have the following code, which is designed to return in JSON format the values from the SQL view:-
public JsonResult GetActivity(string LocalIdentifier)
{
return Json(db.Activities.Where(r => r.LocalIdentifier== LocalIdentifier).ToList(), JsonRequestBehavior.AllowGet);
}
When I try to run this, supplying a valid LocalIdentifier nothing happens for a while and then I get an exception (unhandled in user code) in Visual Studio. For reference, this would generally only return between 30 and 50 rows of data from SQL.
Looking at the Inner Exception I get this error:-
"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."
I've done something similar elsewhere in my application and it works fine - I can't see anything wrong with my code in MVC. Is there anything else I could look at to help diagnose and fix this issue?
Update
Interestingly I've just changed the code to extract just one row (just to see what happens - see below) and it runs instantly...could this be a problem with ToList()?? Is there another way of achieving what I'm trying to do that I could try?
public JsonResult GetActivity(string LocalIdentifier)
{
return Json(db.Activities.First(r => r.LocalIdentifier== LocalIdentifier), JsonRequestBehavior.AllowGet);
}
you should try running the resulting query directly on the sql server. I expect that the query runs for more then 30s, resulting in a timeout. The default timeout value is 30s, so the behaviour you're seeing is expected.
2 ways to deal with it:
speed up the query (maybe you're missing an index?)
change the default timeout (but this is not the preferred option in my opinion)
It depends on how db.Activities is defined. If it has properties for other entities (meaning other tables in the database) then these could also be loaded by EF, even though you did not specify so explicitly, because JSON is serializing each object and its properties. Half your database or more could end up being loaded, even from a simple statement like this.
This SO question has several answers that may help you understand better what is going on behind the scenes, and then fix it.
Enable profiling and see the query inside
Launch this query in SSMS and build the query execution plan
Analyse the plan and make the updates to the database - change structure, build index, change query
If the query runs fine in DB then it seems something wrong with your ORM side part and you should search for the problem there

Potentially dangerous Request.Form value detected (even if the value doesn't exist)

So, as the title say, I am running into this particular error randomly. When I select a particular search criteria, and then use paging events to move to next page, system throws this error.
Funny thing is, not only the search criteria has to specific, but the value doesn't exist. According to .Net, this is the error
A potentially dangerous Request.Form value was detected from the client (objListOfMR^MRHD_MR_Description~7="...ion ASMSD <asmsd#autoshell.com...").
Where MR description is the text field taken from database. So, I checked the database, and the actual value is
Alarm P on PSM unit
No other field has that line <asmsd#autoshell.com anywhere. All records on Page 2 or further of the search result, show this error.
I tried the same thing on the test database (copy of live database), and that worked wonderfully. without any errors.
So, first thing I want to do is, know where is this line coming from. And why is it not coming for test database.
I know how to do a quick hack to fix this, but that's not what I want to try right now.

How to get address (street) using C#?

I'm executing my query and it works fine when I'm using the following ColumnSet.
...
ColumnSet = new ColumnSet(
"name",
"address1_postalcode",
"beep_cin",
"telephone1",
//"address1_street1",
"address1_city"),
...
However, when I uncomment the street reference, I get an error telling me that such an attribute doesn't exist. I'm guessing it's got to do with the control being composite.
How can I access in CRM 2013 the equivalent of address1_street1 in CRM 2011?
Why can I access the other address_... fields like I'm used to but not street1?
Edit
I discovered also that even on the client, using JavaScript, there seems to be something weird. Let's try to run the following two lines (frames[0] is there because that's how it works in IE console window, F12).
frames[0].Xrm.Page.getAttribute("address1_street1").getValue()
frames[0].Xrm.Page.getAttribute("address1_city").getValue()
While the first one gives me Stockholm, the seconds yields an error because the returned attribute is null, despite the fact that I've entered the street as supposed to. Furthermore, I notice that the following line:
frames[0].Xrm.Page.getAttribute("address1_composite").getValue()
returns the whole composite address text - street, city, country etc. In that attribute, there's an object called controls but I didn't find anything useful in it. This is weird and unexpected. I don't like the combination of weirdness and unexpectedness.
Please note that it's the CRM13 version that the weirdification occurs in.
Of course, I could use this atrocity below but is that really what we want to see on the screen of every CRM developer?! It makes my eyes bleed and my will to live withers.
Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_line1")
Besides, I still don't get the value and I still can't see how to use it in C#!
I don't know which entity you want to retrieve, but normally the logical name for Address 1: Street1 field is address1_line1
Here the Attribute Metadata for Account entity:
http://msdn.microsoft.com/en-us/library/gg328057(v=crm.5).aspx#bkmk_attributes

Error when trying to create/update a custom form

I've been assigned to work on a project that uses the AtTask API to create an issue and accompanying custom form from a web application I've built for our intranet. I've been using this post, ATTask API - Updating Custom Field with API and C Sharp, as my main starting reference for accomplishing my task.
Like that post, I'm also getting (500) Internal Server Error, though the error I receive the URL is inserted directly into the browser is {"error":{"class":"com.attask.util.json.JSONException","message":"org.codehaus.jackson.JsonParseException: Unexpected character ('S' (code 83)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: java.io.StringReader#45c828e1; line: 1, column: 6]"}}.
My URL looks like this:
https://myCo.attasksandbox.com/attask/api/v3.0/optask?method=put&projectID=myID&name=API%20SandBox%20Issue&updates={DE:Service%20Affected:Electronic%20Communications,DE:Technical%20Details:I%20dunno,DE:How%20will%20this%20change%20be%20communicated?:It%20wont}&username=myUserName&password=myPassword
I have noticed that one difference between the post I reference above and my URL is that the other post's URL is looking for a categoryID. Is that necessary for working with Custom Forms? If so, where do I find that ID? (I did a search query on an issue that had custom form of the kind I'm trying to generate, but no categoryID was returned).
By the way, my search query looks like this:
Console.WriteLine("**Searching for Change Management Issues");
JToken cmIssues = client.Search(ObjCode.ISSUE, new
{
projectID=cmProjID,
name="SandBox Issue",
name_Mod="contains",
fields="parameterValues"
});
foreach (JToken issue in cmIssues["data"].Children())
{
Console.WriteLine(issue["name"]);
Console.WriteLine(issue["categoryID"]);
Console.WriteLine(issue);
}
I've used both ISSUE & OPTASK ObjCode types, with no luck on the categoryID.
Try removing the sessionID. At the end you are using your username & password, you do not need both. Make sure you spell password correctly. In your example you spelled it wrong.
If that does not work. Make sure all the spaces are replaced with %20 by UrlEncode it before you send the call.
After finally being able to come back to this project, I found that my problems lay with my unfamiliarity with JSON calls. For this particular issue, (after the I fixed the spelling of password), I was receiving my error because I had surrounded neither the custom form object I was sending nor the related value in quotation marks.
Basically, my problem was that I was doing this:
DE:The Object:The Value
when I should have been doing this:
"DE:The Object":"The Value"

Reordering Excel Table Columns with Filters Intact

I am running into an issue with Excel 2007 via VSTO 3.0. In my project, I need to shuffle columns around occasionally. Normally, this works fine but I have recently found that an issue arises when the data is filtered and the fitlered data is non-contiguous.
For example, using this data set:
Ohio Eastern
Kentucky Eastern
Illinois Central
California Pacific
Florida Eastern
If the filter on column two excludes either Pacific or Central, the following code produces an error.
ListObject table = FindReportTable();
// Get data to shuffle around.
ListColumn tempColumn = table.ListColumns.Add(missing);
Range range1 = table.ListColumns[column1].Range;
Range range2 = table.ListColumns[column2].Range;
Range tempRange = tempColumn.Range;
// Swap the rows.
range1.Copy(tempRange); // This is where an error is thrown.
range2.Copy(range1);
tempRange.Copy(range2);
tempColumn.Delete();
The error thrown is a System.Runtime.InteropServices.COMException with an error code of -2146827284 and message "That command cannot be used on multiple selections".
I have tried many things and none seem to work completely. If I use table.AutoFilter.ShowAllData(), I can continue with no problems, but I have then cleared the user's filters and cannot get them back with table.AutoFilter.ApplyFilter() as I assumed.
I cannot reliably store and recreate the filters for two reasons: one, iterating through table.AutoFilter.Filters and storing the filter's data can cause problems if the dataset in the filter is too large. Referring to my example data, if the filter was to exclude Central from column 2, attempting to retrieve the filter's information causes an interop error. Second, to recreate the filter, I need to know what row the filter was originally on to pass into the table.Range.AutoFilter(object, object, XlFilterOperator, object, object) method.
I have been banging my head against this for too long now, and can't seem to find a solution in my own head or on the vast internets. Any help would be much appreciated.
I would look into removing and recreating the filters. If you're seeing problems, then you should fix those problems.
Look at the ListObject.AutoFilter.Filters collection.
Look here for more information.

Categories