Trying to access ContactEndpointCollection in Microsoft Lync - contacts

I am trying to get access to all the endpoints that a particular contact might have so that I can display them, and the only place I have been able to find such a collection in the documentation is in the ContactEndpointCollection. However, despite all my searching I cant seem to find how you can get this collection from a particular Contact.
So my question is this: given a Contact, how can I get their ContactEndpointCollection?

You need to use the GetContactInformation method to get the contact endpoints.
Contact c;
List<object> endpoints = c.GetContactInformation(ContactInformationType.ContactEndpoints) as List<object>;
foreach(object o in endpoints)
{
ContactEndpoint ce = o as ContactEndpoint;
// Stuff
}
This returns an object, which you will need to cast to a list of objects. Then you can iterate through that list, casting each element as a ContactEndpoint. I don't know how to avoid the double casting, I am sure there is a way but this is a workaround.

Related

How to get column title for each row entry

I am using a row id to obtain the cells for a single row. However, the response returns the column id but not the title of the column. In an attempt to make the code readable for others it would be helpful to also obtain the column title. I was thinking of doing this by using the column id that is obtained in the getRow function but I am not entirely sure how to catch it. Below is the basic getRow function for reference. I appreciate any assistance. Thank you in advance all.
smartsheet.sheets.getRow(options)
.then(function(row) {
console.log(row);
})
.catch(function(error) {
console.log(error);
});
My preferred way of addressing this is to dynamically create a column map on my first GET /sheets/{sheetId} request.
Let's say we have a sheet with three columns: Japan, Cat, and Cafe. Here is one way to make a column map.
const columnMap = makeColumnMap(<your sheet data>);
function makeColumnMap(sheetData){
const colMap = {};
sheetData.columns.map( column => colMap[column.title] = column.id);
return colMap;
}
Now, you can reference your specific columns like this: columnMap["Japan"], columnMap["Cat"], and columnMap["Cafe"] or you can use dot notation if you prefer.
Basically, what we're doing is creating a dictionary to map the column titles to the corresponding column id.
Posting this as a separate answer based on your response (and for easier formatting).
I have a couple specific recommendations that will help you.
Try to consolidate your API calls.
I then want to use that columnID to call getColumns(columnId) to obtain the title.
This is 'work' that you don't need to do. A single GET /sheets/{sheetId} will include all the data you need in one call. It's just a matter of parsing the JSON response.
Use this as an opportunity to improve your ability to work with JSON.
I do not know how to catch the columnId once getRow() is called.
The response is a single object with nested arrays and objects. Learning to navigate the JSON in a way that makes sense to you will come in really handy.
I would recommend saving the response from a GET sheet call as it's own JSON file. From there, you can bring it into your script and play with your logic to reference the values you want.

SharePoint 2013 REST Query By ContentTypeId

I am trying to get all the folders items inside of a list. I know that folder content types start with 0x0120. So I wrote these two queries
http://sharepoint.com/sites/dev3/_api/web/lists/getbytitle('Discussions')/items?$filter=substringof(%270x0120%27,ContentTypeId)
This returns no results.
(this was a solution recommended in this thread OData substringof or startswith returning all items)
I also tried
http://sharepoint.com/sites/dev3/_api/web/lists/getbytitle('Discussions')/items?$startswith(%270x0120%27,ContentTypeId)
This returns results but it returns everything ... it does not really do the filtering based on the ID specified by me.
i also tried
http://sharepoint.com/sites/dev3/_api/web/GetFolderByServerRelativeUrl('/sites/dev3/lists/Discussions')/folders
This gives results... but does not return details like the Item Id which I need.
My end object is that if there is a list which has a folder called Foo and an Item called Bar. the query should fetch only the Foo folder and give me details like the etc.
I am looking for a REST solution (no CAML). so far the soltuions which I have tried either return everything Foo and Bar. or nothing.
Found the answer. putting it here so that it helps someone
web/lists/getbytitle('List)/items?$filter=startswith(ContentTypeId,'0x0120')

SugarCRM: How to retrieve complex SQL statements with sugar internal functions?

In order to retrieve a contact, having a cell phone number of 09362724853, I use following code:
$newSMS_contact = new Contact;
$newSMS_contact->retrieve_by_string_fields(array('phone_mobile'=>'09362724853'));
How about retrieving a contact having a cell phone number of 09362724853 OR 9362724853 OR +989362724853 with sugar internal functions?
This doesn't work:
$newSMS_contact = new Contact;
$newSMS_contact->retrieve_by_string_fields(array('phone_mobile'=>'09362724853', 'phone_mobile'=>'9362724853', 'phone_mobile'=>'+989362724853'));
The thing is that the function which you are trying to utilize was created for other goals. Since it fetches only one row from DB and fills a Bean with it, the Array of parameters will be turned into a string separated by AND operators. But you have completely different case.
I would suggest to use another approach, which is less convenient but more reliable:
$contact_bean = new Contact();
$contacts_list = $contact_bean->get_full_list(null, '(phone_mobile = "09362724853" OR phone_mobile = "9362724853" OR phone_mobile = "+989362724853")');
Eventually, you will have an array of beans.
Probably, for some modules, you will need to use table aliases for fields definition into SQL supplement.
If I were you, I'd have strict rules when the phone numbers are put in the system so you can be sure your phone numbers follow a certain format in the database. (Something like E.164: http://en.wikipedia.org/wiki/E.164) You can enforce the rules with a custom SugarField (or override one that exists) that has Javascript and Server-side validation.
This way, you won't have to worry about that logic in this piece of the code or anywhere else you want to deal with phone numbers.

Get statuscode text in C#

I'm using a plugin and want to perform an action based on the records statuscode value. I've seen online that you can use entity.FormattedValues["statuscode"] to get values from option sets but when try it I get an error saying "The given key was not present in the dictionary".
I know this can happen when the plugin cant find the change for the field you're looking for, but i've already checked that this does exist using entity.Contains("statuscode") and it passes by that fine but still hits this error.
Can anyone help me figure out why its failing?
Thanks
I've not seen the entity.FormattedValues before.
I usually use the entity.Attributes, e.g. entity.Attributes["statuscode"].
MSDN
Edit
Crm wraps many of the values in objects which hold additional information, in this case statuscode uses the OptionSetValue, so to get the value you need to:
((OptionSetValue)entity.Attributes["statuscode"]).Value
This will return a number, as this is the underlying value in Crm.
If you open up the customisation options in Crm, you will usually (some system fields are locked down) be able to see the label and value for each option.
If you need the label, you could either do some hardcoding based on the information in Crm.
Or you could retrieve it from the metadata services as described here.
To avoid your error, you need to check the collection you wish to use (rather than the Attributes collection):
if (entity.FormattedValues.Contains("statuscode")){
var myStatusCode = entity.FormattedValues["statuscode"];
}
However although the SDK fails to confirm this, I suspect that FormattedValues are only ever present for numeric or currency attributes. (Part-speculation on my part though).
entity.FormattedValues work only for string display value.
For example you have an optionset with display names as 1, 2, 3,
The above statement do not recognize these values because those are integers. If You have seen the exact defintion of formatted values in the below link
http://msdn.microsoft.com/en-in/library/microsoft.xrm.sdk.formattedvaluecollection.aspx
you will find this statement is valid for only string display values. If you try to use this statement with Integer values it will throw key not found in dictionary exception.
So try to avoid this statement for retrieving integer display name optionset in your code.
Try this
string Title = (bool)entity.Attributes.Contains("title") ? entity.FormattedValues["title"].ToString() : "";
When you are talking about Option set, you have value and label. What this will give you is the label. '?' will make sure that the null value is never passed.

sorting people by their role on a company

Im trying to find a good way to sort people by their Role within a specific company. What makes it tricky, is that a person can have one or more roles in different companies.
At the moment I have an array of 'Person' objects, and each of these objects has a NSSet of 'Roles' objects associated to it.
Similar to this:
Person
-personId
-personName (NSString)
-personRoles (NSSet)
Role
-roleId (NSNumber)
-roleWeight (NSNumber)
-roleName (NSString)
-companyId (NSNumber)
I need some code that is able to solve something similar to this:
Sort Array of Person by Role.roleWeight Where Role.companyId = X
I have been looking at the Sort Descriptors, but they dont seem to be enough to solve the challenge. Any suggestions are welcome.
You'll want to look at this
How to sort an NSMutableArray with custom objects in it?
The basic idea is that given any two Person objects, you have to say how they compare. Is one less, greater, or are they the same.
- (NSComparisonResult)compare:(id)otherObject {
// get the role for self
// get the role for other object
// compare their weights
// return the right result
}
To pass in the company id, I think you'll need sortUsingFunction:context:, with a function like this
static int comparePersonsUsingCompanyID(id p1, id p2, void *context)
{
// cast context to a company id
// get the role for p1
// get the role for p2
// compare their weights
// return the right result
}
Assuming that you use NSArray to store data (on maybe CoreData store) you can use NSArrayController. Controller supports sort descriptors and NSPredicate as well. In your case you need a predicate to filter people (where role.companyId = x) and sort descriptors to sort by roleWeight.