Get SharePoint User by Lookup ID using Microsoft Graph - sharepoint

I perform the following query in Microsoft Graph:
var results = await SPLists["<my-list-name>"]
.Items
.Request()
.Expand("fields")
.GetAsync();
It gets the list items of a list I have in SharePoint. One of the columns in that list is of type "Person or Group". In the response from Microsoft Graph, it returns that column data like this (for example):
{
"LookupId": 335,
"LookupValue": "John Doe"
}
How do I take advantage of this data? How do I get the full profile of person with ID 355 using the Microsoft Graph? I need the email address of the person returned. How do I get that using the Microsoft Graph SDK?

The Look Id 335 is the Id in the SharePoint Hidden List named "User Information List", you can get the list guid using the request:
https://graph.microsoft.com/v1.0/sites/site-id/lists?$filter=DisplayName eq 'User Information List'
Then use the list guid in the endpoint below to get the detail email address:
https://graph.microsoft.com/v1.0/sites/site-id/lists/UserInformationListId/items/335
Here is a similiar thread for your reference:
How to get user from User field LookupId

Related

NetSuite: Need to get value Of Landed Cost Category Line Field using Transaction Saved Search

I am trying to somewhat mimic NetSuite's Landed Cost feature using NetSuite's customization options (SuiteBuilder,SuiteScript etc.) and then further extend the functionality according to my requirements.
For this I need to in script, get value of "LANDED COST CATEGORY" line field of item sublist in the Transaction records (like Bill, Purchase Order etc.) using saved search.
But in a saved search I was unable to find any Column/scriptId which would give me value of LANDED COST CATEGORY line field. We ARE able to get this value using record.load().getValue() but I need this value from multiple transaction records and using this approach may cause performance issues. So, please can you tell how we can access this value using saved search.
I don't believe Netsuite exposes that field in saved searches at this time. This is the records browser in Netsuite listing all of the available search columns for Transaction searches. The internal id for that column is landedcostcategory, and that doesn't show up on the list.
However, if your goal is to get this information in SuiteScript, then you can use the 'N/query' module. Pull up one of your Purchase Orders, open the Javascript console (Ctrl+Shift+J) and try this:
require(['N/query'], (query) => {
const suiteqlQuery = `SELECT
transaction as transaction_id,
BUILTIN.DF(transaction) as transaction_name,
BUILTIN.DF(item) as item_name,
item as item_id,
landedcostcategory as landedcostcategory_id,
BUILTIN.DF(landedcostcategory) as landedcostcategory_name
FROM
transactionline
WHERE
transaction='<internal id of your PO here>'`;
const results = query.runSuiteQL({query: suiteqlQuery}).asMappedResults();
console.log(JSON.stringify(results, null, 2));
/*
Example output for results:
[
{
"transaction_id": "12345",
"transaction_name": "Purchase Order #PO123456",
"item_name": "My Favorite iPod",
"item_id": 1234,
"landedcostcategory_id": 1,
"landedcostcategory_name": "Duties & Tariffs"
}
]
*/
})

How do I do a joined lookup with search.lookupFields()?

I'm trying to get some information about an item, including the item's subsidiary's logo, which naturally requires joining the item to the subsidiary.
The documentation for search.lookupFields says:
You can use joined-field lookups with this method, with the following syntax:
join_id.field_name
So, I duly request the fields I want, including a join on subsidiary:
require(['N/search'], function(search) {
var item = search.lookupFields({
type: search.Type.ITEM,
id: 2086,
columns: ['itemid', 'displayname', 'subsidiary.logo'],
});
log.debug(item);
});
itemid and displayname are fine, but when I try to join another record I get this error:
{
"type":"error.SuiteScriptError",
"name":"SSS_INVALID_SRCH_COLUMN_JOIN",
"message":"An nlobjSearchColumn contains an invalid column join ID, or is not in proper syntax: logo.",
"stack":["doLookupFields(N/search/searchUtil.js)","<anonymous>(adhoc$-1$debugger.user:2)","<anonymous>(adhoc$-1$debugger.user:1)"],
"cause":{
"type":"internal error",
"code":"SSS_INVALID_SRCH_COLUMN_JOIN",
"details":"An nlobjSearchColumn contains an invalid column join ID, or is not in proper syntax: logo.",
"userEvent":null,
"stackTrace":["doLookupFields(N/search/searchUtil.js)","<anonymous>(adhoc$-1$debugger.user:2)","<anonymous>(adhoc$-1$debugger.user:1)"],
"notifyOff":false
},
"id":"",
"notifyOff":false,
"userFacing":false
}
This seems to happen no matter which record and field I try to join. What am I missing?
Although you can return results from multi-select fields, you cannot join to fields on records referenced by multi-select fields (which the subsidiary field on the item record is). Also, you cannot search the logo field on the subsidiary record (not listed in Search Columns under Subsidiary in the NetSuite Records Browser).
This means you have to load the Subsidiary record to get the logo field. In other words:
require(['N/record', 'N/search'], function(record, search) {
var item = search.lookupFields({
type: search.Type.ITEM,
id: 2086,
columns: ['itemid', 'displayname', 'subsidiary'],
});
var subID = item.subsidiary[0].value; //internal id of *first* subsidiary
var subRec = record.load({
type: record.Type.SUBSIDIARY,
id: subID
});
var logo = subRec.getText('logo'); //gets the file name - use getValue to get its ID instead
});
Note that if multiple subsidiaries are set on the item, this only gets the values for the first one. You could iterate through the item.subsidiary result to handle values for multiple subsidiaries if required.
I believe you can't access to the subsidiary record from a lookupfield, you should do a proper search.
https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2018_2/script/record/item.html
You can only join to tables allowed in the Item search object. Try looking for "Subsidiary..." in the Search Results tab within the UI. It's not there. Use the Schema Browser to determine what fields and joins are available.
You cannot think of a NetSuite search as you would any regular SQL search. You have to be cognizant of which fields and which joins can be utilized via the search object.
As people have mentioned, the subsidiary is not a join field available from the item record, one way to achieve what you are trying to do is:
Make a lookup to get the internal id of the subsidiary belonging to the desired item.
Then make a lookup to get the internal id of the logo image (file cabinet image) belonging to the previous subsidiary.
Make another lookup/load the image file to get the URL of the image/logo
You can try to combine the above steps in a single saved search but I think you might need to load the image file to get the URL.
This won't answer your question, but this may help out in the future. The records browser shows everything that you can search and join on, columns and filters, and field IDs. Very useful when building out searches.
NetSuite Records Browser - 2018.2

SharePoint - KQL - Department property contains value

Requirement: I do have "People search" webpart and I need to return ONLY users with a value associated to Department property.
Additional comments:
If in the SharePoint User Profile, the department property does not hold any value, I don't need to return this specific user.
I expected to have this one (below) working but it still returns users with no values associated to the Department property
{searchboxquery}* Department<>""
Thanks
Can't filter based on empty value directly, you could check the 'workaround' here.
Department:a*
Department:b*
Department:c*
Department:d*
Department:e*
Department:f*
Department:g*
Department:h*
Department:i*
Department:h*
Department:k*
Department:l*
Department:m*
Department:n*
Department:o*
Department:p*
Department:q*
Department:r*
Department:s*
Department:t*
Department:u*
Department:v*
Department:w*
Department:x*
Department:y*
Department:z*

CRM 2011 oData query confusion

I am very new to CRM development, i was trying to follow this article, i am a bit confused about below code, please check:
var xp = Xrm.Page;
function onLoad(context) {
var accountId = xp.data.entity.getId();
var mostRecentQuery = "/XRMServices/2011/organizationData.svc/ContactSet?
$select=FullName,JobTitle,EMailAddress1,Telephone1&$top=1&$orderby=CreatedOn
desc&$filter=ParentCustomerId/Id eq guid'" + accountId + "'";
getContact(mostRecentQuery, "MostRecent");
....
}
The above javascript function executes when AccountForm is opened. The first line gets the accountId. the next line is oData query.
Now check the ContactSet in this query, i am confused here, how we can retrieve the ContactEntity based on the GUID of AccountEntity?
I found the answer!
Actually there a Lookup 'Parent Customer' on ContactEntity, it represents the unique identifier of the account or contact associated with this contact, so we can select an Account/Contact as the Parent Customer of a contact.
So this given OData query actually retrieves the top 1 contact where this account is referenced.
I hope its clear.

Get SPListItem in another format

I want to get different Rows from an SPListItem. I'll show you my problem with an example.
This code
Console.WriteLine(SPItemName["Created By"]);
or
Console.WriteLine(SPItemName["Created By"].ToString);
returns "8;UserName" (8 is the User ID).
If I look up the row in SharePoint Designer, i can choose even a format for this data field.
So i could get the html code of this field.
How to set the format (like html code or text) of a datafield in c#?
thanks
Use Either SPFieldLookupValue
If you need just the username, use SPFieldLookupValue to seperate id from value:
var userValue = new SPFieldLookupValue(SPItemName["Created By"] as string)
Then you can:
userValue.LookupValue to return UserName
userValue.LookupId to return Id
Or SPFieldUserValue
Or better yet, you can create SPFieldUserValue object to access any other user properties like email, login name, etc..
SPFieldUserValue objUserFieldValue = new SPFieldUserValue(web, SPItemName["Created By"].ToString());
Afterwards you can use:
objUserFieldValue.User.LoginName;
objUserFieldValue.User.Name;
objUserFieldValue.User.ID;
objUserFieldValue.User.Groups;
objUserFieldValue.User.Roles;
objUserFieldValue.User.Email;
objUserFieldValue.User.Sid;
objUserFieldValue.User.UserToken;
http://www.sharepointkings.com/2009/04/spfielduservalue-and.html
Note: to create SPFieldUserValue you must pass reference to web, that's because SharePoint has to get additional user information from user information list to construct SPFieldUserValue object.

Resources