linqToTwitter UserID always zero - linq-to-twitter

I need to construct the URL to the original tweet as
http://twitter.com/{twitter-user-id}/status/{tweet-staus-id}
Joe's code on linq2twitter works fine, but when I replace User.ScreenNameResponse from his sample with User.UserID,
the UserID is always zero. The debugger shows tweet.UserID is also zero. Most fields are populated.
My code:
var twitterCtx = new TwitterContext(getAuth());
var searchResponse =
await
(from search in twitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == searchTxt &&
search.Count == searchCount
select search)
.SingleOrDefaultAsync();
if (searchResponse != null && searchResponse.Statuses != null)
searchResponse.Statuses.ForEach(tweet =>
Console.WriteLine(
"User: {0}, Tweet: {1}",
//tweet.User.ScreenNameResponse,
tweet.User.UserID,
tweet.Text));
Version: 3.1.1 from NuGet using app authentication.
How can I get the UserID so I can construct the tweet URL?
This SO thread (use id_str) did not help.

That would be in tweet.User.UserIDResponse.
A bit of background: Anything used as an input parameter is also looked at in the query response, so if a user omits the parameter in a query but the twitter response contains a value, it was being filtered out of the results. To fix this, I adopted a convention where any return parameters also match input parameters would have a 'Response' suffix. e.g. ScreenName (input) and ScreenNameResponse (output). To find which values are input, the docs for each API (including Search) call contain the input/filter parameters.

Related

Dynamics CRM 2013: How to check whether an contact already got a connection to a record?

we've got multiple companys (entity "Account") in our Dynamics CRM 2013, which can have multiple employees (entity "Contact"). We connect them (entity: "Connection") together.
One employee can work for multiple companys at the same time.
It should be possible to connect an employee to the same company again, if the field "EffectiveEnd" (entity "Connection") is not empty.
I wanted to use the SDK this way:
If field "Record1" contains data, catch all records in the entity "connection", where the Name is identical.
This way, I could check in the next step, whether the field "EffectiveEnd" contains data and if not, break the function.
I used the following code:
function validateContact() {
if (Xrm.Page.data.entity.attributes.get("record2id").getValue() != null) {
var primaryContactName = Xrm.Page.data.entity.attributes.get("record2id").getValue()[0].name;
var paramType = "Connection";
var paramOptions = "$select=EffectiveStart&$filter=Record2RoleId/Name eq " + primaryContactName + "";
var strQueryResult = SDK.REST.retrieveMultipleRecords(paramType, paramOptions, retrieveSuccessCallback, errorHandler, retrieveComplete);
}
else {
// alert("empty");
return;
}
}
but I'm getting error 400 (own translation at the error messages):
var paramOptions = "$select=EffectiveStart&$filter=Record2RoleId/Name eq " + primaryContactName + "";
results in
Error: 400: Bad Request: No Property 'Schulz' in type 'Microsoft.Xrm.Sdk.Entity' at position 22.
and
var paramOptions = "$select=EffectiveStart&$filter=Record2RoleId/FullName eq " + primaryContactName + "";
results in
Error: 400: Bad Request: No property 'FullName' in type 'Microsoft.Crm.Metadata.ComplexTypeinstance'1[[Microsoft.Xrm.Sdk.EntityReference, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=XXXXX]]' at position 14.
Thanks in advance!
:e Typos
I'm guessing your SDK.REST.retrieveMultipleRecords is the same function demonstrated here.
In which case you are effectively doing this:
SDK.REST.retrieveMultipleRecords("Connection", "$select=EffectiveStart&$filter=Record2RoleId/FullName eq " + primaryContactName + ", ...);
In which case you would seem to be trying to query the connection entity using fields that doesnt exist on the connection entity. Fullname is a contact field.
You will need to join from the connection entity to the contact entity via the lookup (EntityReference) fields.
Retrieve related entities by expanding navigation properties
Use the $expand system query option in the navigation properties to
control what data from related entities is returned.
[Organization URI]/api/data/v8.2/accounts?$select=name&$expand=primarycontactid($select=contactid,fullname)
Or, you could change to query directly onto the contact entity. var paramType = "contact";

JSON Show result on partial hit

I have a piece of code which works with JSON to read values from a file, I got it working to display the results I need when I have a full match and a way that shows all the data all the time, both not what I need. I started the code out with a CSV file, but due the amount of data this was too slow, thus the switch to JSON (see: This question)
The code I have now with the JSON is as follows:
$(document).ready(function() {
var airports; //Prepare variable for storing JSON data
d3.json("airport.json", function(data) {
airports = data; //put the JSON data into an easy to call variable
continueCode(); //This is so we can use the JSON data outside of this call
});
function continueCode(){
var result; //Prepare result variable for usersearches
//User is typing in departure field
$(".input-leave").on("keyup paste", function(){
$("#display").empty();
//Grab user input
var userInput = $(".input-leave").val();
if(userInput != ''){
console.log("User input: "+userInput);
//console.log(airports[0]["Country Code"]);
for(var i=0; i<airports.length; i++){
/* Prepare Variables for checking columns of JSON
cnCode = Country Code
ctCode = City Code
stCode = State Code
apCode = Airport Code
apName = Airport Name
*/
var cnCode = airports[i]["Country Code"],
ctCode = airports[i]["City Code"],
stCode = airports[i]["State Code"],
apCode = airports[i]["Airport Code"],
apName = airports[i]["Airport Name"];
//Check if user input matches one of our variables
//This shows the airports on an exact match
if((userInput.toLowerCase() == cnCode.toLowerCase()) || (userInput.toLowerCase() == ctCode.toLowerCase()) || (userInput.toLowerCase() == stCode.toLowerCase()) || (userInput.toLowerCase() == apCode.toLowerCase()) || (userInput.toLowerCase() == apName.toLowerCase())){
$("#display").append("Country Code: "+cnCode+", City Code: "+ctCode+", State Code: "+stCode+", Airport Code: "+apCode+", Airport Name: "+apName+"<hr>");
}
//This results in every airport being shown at all times
if((userInput.toLowerCase().indexOf(cnCode.toLowerCase())) !== -1 || (userInput.toLowerCase().indexOf(ctCode.toLowerCase())) !== -1 || (userInput.toLowerCase().indexOf(stCode.toLowerCase())) !== -1 || (userInput.toLowerCase().indexOf(apCode.toLowerCase())) !== -1 || (userInput.toLowerCase().indexOf(apName.toLowerCase())) !== -1){
$("#display").append("Country Code: "+cnCode+", City Code: "+ctCode+", State Code: "+stCode+", Airport Code: "+apCode+", Airport Name: "+apName+"<hr>");
}
}
}else{
$("#display").empty();
}
});
}
});
As you can see I have 2 ways of reading the data now, one that shows the data on a full string match and one that display all the data at any string.
What I need is for the data to be displayed on a partial string hit (example: user types 'Am', results display everything starting with 'am' in any column).
I have looked around here on SO and on Google, but everything I find is for displaying partial data, where the user sends an input and the result is for example an ID and name, I need to show the data while the user is inserting the data however so that won't work for me, is there a quick and easy way of solving this? I have been unable to find any JSON plugins that could do it for me, I have considered trying it with ElasticSearch, but I'm unsure as to how I should get started on that and if it will do the trick for me.
You can use this Autocomplete Widget | jquery
The basic usage is to specify the source array.

How can I populate fields with information related to single lookup field?

I'm working on a form 'Enrollment Adoptions' in CRM 2015, specifically with three fields; Product, Component, and Editorial. 'Product' is a lookup field referencing the Product Entity. 'Component' and 'Editorial' are simple text fields to be filled using javascript. Each product in the Product Entity has a corresponding component and editorial, which are OptionSets in the product form.
The goal:
I want a function to trigger OnChange with 'Product' that looks to that specific product record, gets its corresponding component and editorial info, and auto-fills the 'Component' and 'Editorial' fields in 'Enrollment Adoptions'.
The problem:
I can't seem to figure out how to get the value from the "product' lookup field and use it to get the information I need.
Here's a bit of code I've been testing:
function populateProduct(blank)
{
if (blank != null || blank != undefined)
{
var productName;
var product = Xrm.Page.getAttribute(blank);
if (product.getValue != null || product.getValue != undefined)
{
productName = product.getValue()[0].name;
console.log("the product name is " + productName);
var componentXml = "<fetch mapping='logical'>"+"<entity name='product'>"+"<attribute name='new_component'/>"+"<filter>"+"<condition attribute = 'name' operator='eq' value='"+productName+"' />"+"</filter>"+"</entity>"+"</fetch>";
var fetchComponent = XrmServiceToolkit.Soap.Fetch(componentXml);
console.log("the respective component is " + fetchComponent);
}
}
}
The log statements are just to test if I'm getting the info I need while testing.
The log statements show me that I'm getting the product name for sure but I'm not getting the corresponding component.
I looked into building queries using Fetch but I don't think I understand them correctly because it isn't getting the info I'm hoping for. Obviously this is very much an incomplete function but I wanted to make sure I was getting the information I needed before writing out the rest.
Any advice?
The response from the fetch call returns objects that you have to dig into, like this:
var componentXml = [
"<fetch mapping='logical'>",
"<entity name='product'>",
"<attribute name='new_component'/>",
"<filter>",
"<condition attribute = 'name' operator='eq' value='"+productName+"' />",
"</filter>",
"</entity>",
"</fetch>"].join('');
var products = XrmServiceToolkit.Soap.Fetch(componentXml);
if (products.length > 0) {
if (products[0].attributes.productid != undefined)
console.log("the product id is", products[0].attributes.productid);
console.log("new_component is", products[0].attributes.new_component);
}
}

How do I pre-fill a PDF Web Form using URL Query String (or better method)?

I need to fill in a PDF Web Form that will be available to the public with data taken from a URL Query String. I don't want the user to be able to edit anything on the form - only print or save it.
I realize this is not the most secure way as they could edit the query string to modify the data. Is there a more secure way?
I am currently trying to do this using the simplest way possible: a pdf form and javascript in the form.
Code follows but has not been tested properly. I am wondering if this is the right approach?
// This code was taken from:
// http://blogs.adobe.com/pdfdevjunkie/2009/12/populating_pdf_form_fields_fro.html
// Accessed: June 15, 2015
//only run the script if the PDF file is being viewed in a browser window
if (this.external)
{
//The whiteList defines which fields are permitted to be changed by the URL.
//If you want all fields to be changed, leave the array empty as in "[]"
//whiteList = ["Name", "Address", "City", "State", "ZipCode"]
whiteList = []
//get the parameters portion of the URL and unescape it so we get the spaces and punctuation back
parametersString = this.URL.substring(this.URL.indexOf("?")+1)
//only run the script if there are parameters
if (parametersString.length > 0)
{
//create an array of key/value pairs
parameters = parametersString.split("&")
//loop through the array...
for each (parameter in parameters)
{
//create a 2 element array for each parameter as [key, value]
kvPair = parameter.split("=")
//set the field named "key" to "value"
fieldName = unescape(kvPair[0])
if (whiteList.length > 0)
{
if (whiteList.indexOf(fieldName) > -1)
{
this.getField(fieldName).value = unescape(kvPair[1])
}
}
else
{
this.getField(fieldName).value = unescape(kvPair[1])
}
}
}
}

JavaScript Function to Pull related object fields

I am using the following query to try to pull fields off of a User lookup on the Account. There is a field on the Account called Dedicated_Rep__c which is a user lookup. I am building my button off the opportunity, and I want to be able to pull the Opportunity's Account's Dedicated Rep's First Name, Last Name, and Email. Here's my code:
function getDedicatedAccountRep (oppId) {
var result = sforce.connection.query("select Account.Id, Account.Dedicated_CS_Rep__r.FirstName from Opportunity where Id = '" + oppId + "' ");
if(!result || result['size'] != 1) {
return null;
}
var DedRepRole = result.getArray('records')[0];
return DedRepRole.Account;
}
var dedicatedRep = getDedicatedAccountRep('{!Opportunity.Id}');
I am getting an error:
Cannot read property 'Dedicated_CS_Rep__c' of undefined
I am referencing the code later in the button and I am instantiating it by putting: dedicatedRep.Dedicated_CS_Rep__r.FirstName
Start with something like that (I prefer the Google Chrome's javascript console, you can open it with Ctrl+Shift+J; but feel free to use Firefox + Firebug or IE's developer tools...)
{!requireScript("/soap/ajax/29.0/connection.js")}
var result = sforce.connection.query("SELECT Account.Dedicated_CS_Rep__r.FirstName FROM Opportunity WHERE Id = '{!Opportunity.Id}'");
console.log(result);
debugger;
This will let you inspect the query result and play with the results. I think your problem is that the full expression can look like this:
result.records.Account.Dedicated_CS_Rep__r.FirstName
A lot can go wrong here. result should be OK and records should be always 1 row since we run it for one Opportunity (let's ignore crazy scenarios where somebody deleted the Opp between you navigating to the page and clicking the button... But still:
the Account can be blank (out of the box it's perfectly valid to have private Opportunities; maybe your organisation has marked the field as required).
And similarly in theory it's valid to have Account without the user.
So - you have 2 chances to hit null pointer exception:
Therefore properly protected code would have this orgy of null / undefined checks:
{!requireScript("/soap/ajax/29.0/connection.js")}
var result = sforce.connection.query("SELECT Account.Dedicated_CS_Rep__r.FirstName FROM Opportunity WHERE Id = '{!Opportunity.Id}'");
console.log(result);
if(result != null
&& result.records != null
&& result.records.Account != null
&& result.records.Account.Dedicated_CS_Rep__r != null){
alert(result.records.Account.Dedicated_CS_Rep__r);
// return result.records.Account.Dedicated_CS_Rep__r;
} else {
alert('Nope');
// return null;
}

Resources