Set the Lookup field to show only Contacts - javascript

I have a lookup field which shows a lookup for 4 entities. So, I have added the PreSearch Filter to filter only the contacts when I click on the field.
But, when I click on Look for more Records, I want the search to be made only on Contacts entity.
I want to see only Contacts entity on the following image :
Is it possible?

It’s not possible to hide those related entities from the list. But we can disallow the users to choose any other unwanted entity records in that lookup.
We have to use addPreSearch and addCustomFilter. For example, to allow users to choose only contact but not account or systemuser, see the following snippet. This will filter out account & systemuser records from the view & users can move forward only by choosing contact.
var contactFilter = "<filter type='and'><condition attribute='contactid' operator='not-null' /></filter>";
//remove accounts
var accountFilter = "<filter type='and'><condition attribute='accountid' operator='null' /></filter>";
    //remove system users
    var systemUserFilter = "<filter type='and'><condition attribute='systemuserid' operator='null' /></filter>";
Xrm.Page.getControl('requiredattendees').addCustomFilter(contactFilter, "contact");
Xrm.Page.getControl('requiredattendees').addCustomFilter(accountFilter, "account");
Xrm.Page.getControl('requiredattendees').addCustomFilter(systemUserFilter, "systemuser");
    
Read more
Edit:
Adding another undocumented (hence unsupported) till 8.x
Xrm.Page.getAttribute('your_field').setLookupTypes(['contact']);
9.x documented & supported way:
Xrm.Page.getControl('your_field').setEntityTypes(['contact']);
Update: (replacement of above deprecated syntax)
function onFormLoad(executionContext) {
var formContext = executionContext.getFormContext();
formContext.getControl('your_field').setEntityTypes(['contact']);
}
Read more

Related

Troubleshooting SuiteScript 1.0 Line Level Field Sourcing Code (List/Record)

I am an inexperience technical developer working on my first SuiteScript using SuiteScript 1.0. I am getting an SSS_MISSING_REQD_ARGUMENT error, but I am sure there are many more in my code. The purpose of the script is to populate the department field on the expense record line item from a joined record. The end user will select a Project on the expense line, and the script should look up the department on the project record (a custom field) and add the value to the native department field. Code is copied below.
function ProjectSegment ()
{
var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());
var recordID = nlapiGetRecordId(record);
//internal ID of project record
var project = nlapiGetField ('custcol_nra_expense_project');
//load project record
var precord = nlapiLoadRecord('job', project);
//get department on project record (internal ID)
var pdepartment = precord.GetFieldValue('custentity_nra_dept_project');
//get project name from project record
var projectName = precord.GetFieldText('entityid');
//load existing search
var search = nlapiLoadSearch('job','customsearch161');
//add filter to include project name
search.addFilter(new nlobjSearchFilter('entityid',null,'is',projectName));
//run search
var resultSet = search.runSearch();
//get department line
var departmentResult = new nlobjSearchColumn('custentity_nra_dept_project');
//set value
nlapiSetFieldTexts('job','department',1,departmentResult)
//record.commitLineItem('department');
nlapiSubmitRecord(record, true);
}
//internal ID of project record
var project = nlapiGetFieldValue ('custcol_nra_expense_project');
Praveen Kumar's response is correct regarding the missing required argument, but there are many other issues with the script as you've surmised.
Side notes:
The getFieldValue and getFieldText methods of nlobjRecord are not capitalized.
For performance reasons, you could/should use a search to get the values you need from the job record. Loading a record just to get field values is wasteful unless you mean to change the record.
Your search filter should probably be based on the value (not text) of the entityid in the job record.
Your desired search column probably is invalid (I don't think a custentity field could be on a job record).
Getting the search result is incorrect.
You want something like this instead:
var result = resultSet.getResults(0, 1);
if (result) {
var department = result.getValue('custentity_nra_dept_project');
// etc.
}
All that said, though, from your description, I don't think you need the search anyway. Once you have pdepartment (again, using precord.getFieldValue), I think all you need is:
record.setFieldValue('department', pdepartment);
Or if you're setting the line-level department, it would be different.
What kind of script is this? I'd like to make more recommendations, but it depends on what's going on.

Get all user properties from Microsoft graph

We have an application which has used a local AD to fetch user info. Some customers want to move to the cloud and are using Azure AD. We extended the app to sign users in via owin and now we're fetching users via Microsoft Graph.
However from Microsoft Graph we do not get full user profiles. We want to fetch all properties on users, not just the basic ones.
var client = new RestClient(string.Format("https://graph.microsoft.com/v1.0/users/{0}", userEmail));
request = new RestRequest();
request.Method = Method.GET;
request.AddHeader("Authorization", _token.Token);
var reponse = client.Execute(request);
This only gives me some information though, for example I don't get 'Department' from this.
Is it possible to configure in azure what should be returned here, if so then where? Or do I need something other than /users/?
Different customers might have different special properties that need to be fetched. So the best solution would be to have an endpoint to call and get everything, including special properties not standard in azure ad. After that I can parse it on my side. Is this possible?
The app has permission to read both basic and full profiles. Do I need something more?
That's the normal behaviour of Graph API, see documentation here and this extract:
By default, only a limited set of properties are returned (
businessPhones, displayName, givenName, id, jobTitle, mail,
mobilePhone, officeLocation, preferredLanguage, surname,
userPrincipalName).
To return an alternative property set, you must specify the desired
set of user properties using the OData $select query parameter. For
example, to return displayName, givenName, and postalCode, you would
use the add the following to your query
$select=displayName,givenName,postalCode
You have to specify all fields in the select, as $select=* will only output the key fields in Graph API implementation.
So you will not be able to get what you ask (variable custom fields).
More info on the fields of User can be found here
User user = await graphServiceClient
.Users[emailId]
.Request()
.Select(aadUser => new
{
aadUser.Id,
aadUser.UserPrincipalName,
aadUser.DisplayName,
aadUser.GivenName,
aadUser.Surname,
aadUser.City,
aadUser.MailNickname,
aadUser.UserType
})
.GetAsync()
.ConfigureAwait(false);
As already stated by NicolasR, you must list all the fields you want to retrieve by using the "$select" parameter; if you want, instead, to retrieve the custom fields, you can either add them to the previous parameter (if you know their names) or you can use "$expand=extensions"
function getGraphDataAdvanced($authToken, $urlGraph){
$url = $urlGraph + '&$count=true'
$data = (Invoke-RestMethod -Headers #{
Authorization = "Bearer $($authToken)"
ConsistencyLevel = "eventual"
} -Uri $url -Method Get)
$dataList = #()
$dataList += $data.value
$url = $data.'#Odata.NextLink'
while ($null -ne $url){
Write-Warning 'Retreiving Next Page'
$data = (Invoke-RestMethod -Headers #{
Authorization = "Bearer $($authToken)"
ConsistencyLevel = "eventual"
} -Uri $url -Method Get)
$dataList += $data.value
$url = $data.'#Odata.NextLink'
}
return $dataList
}
getGraphDataAdvanced $authToken 'https://graph.microsoft.com/beta/users? $expand=extensions'
Using the Microsoft Graph Explorer, I've been able to find all available properties for a user:
Go to "Groups"
Select "list all groups in my organization"
Change the query to filter by a group you know and expand members: https://graph.microsoft.com/v1.0/groups?$filter=mail eq 'aGroup#company.com'&$expand=members
Now you'll see all the available properties for the users.
I've been trying to find a way to get all Azure AD properties of objects via Powershell MSGraph cmdlets without it truncating at the right edge of the console.
I've discovered that Format-Custom triggers vomiting of (apparently) all properties of an object in a huge, alphabetical, indented, and bracketed list.
Get-MgUser -filter "startswith(userprincipalname, 'username')" | format-custom
The formatted properties of a newly created and unused user account in Azure AD is 13217 lines long.

Suitescript Scheduled Script ERROR: SSS_MISSING_REQD_ARGUMENT Details: id

I am trying to write a simple scheduled script to copy the total YTD Sales of a Sales Rep onto the Employee record daily. I was able to pull this information using a summary search, however, I am unable to Store the Value due to limitaions in the system. So I cannot query against that total with future searches/workflows. As a work around the only way I found possible to accomplish this is a daily scheduled script that will run the summary search and then copy the result for each Sales Rep into a custom field on the employee record. However when running it fails and I get the following error:
SSS_MISSING_REQD_ARGUMENT Details: id
The summary search is a transaction search grouping all transactions with a filter of Sales Rep:InternalId
Here is the code I am using. Thank you for your help.
function copyValues(){
var saleSearch = nlapiLoadSearch('transaction', 'customsearch_abi_totalsalesbyrep');
var resultSet = saleSearch.runSearch();
resultSet.forEachResult(function(searchResult){
var employeeId = searchResult.getValue('salesrep.internalid');
var employeeRec = nlapiLoadRecord('employee', employeeId);
employeeRec.setFieldValue('custentity_abi_ytdsalesstatic', employeeRec.getFieldValue('custentityabi_totalsalebyrep')); // Copy Total YTD Sales
nlapiSubmitRecord(employeeRec);
return true;
});
}
Have you checked if the variable employeeId is populated?
var employeeId = searchResult.getValue('salesrep.internalid');
For getting values from search results, I use this format
searchResult.getValue(<field id>,<join id>)
So in this case it would be
searchResult.getValue('internalid','salesrep')
Sublists are mandatory even if empty.

Escape & character with DocuSign Custom Button

I have a button that I created but I'm having issues with it working when Account Name has the & symbol in it. When & is added, it completely clears out the rest of email subject. I tried adding a JSENCODE and that didn't solve the problem. Is there another way that I can get this to work?
{!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript")}
//********* Option Declarations (Do not modify )*********//
var RC = '';var RSL='';var RSRO='';var RROS='';var CCRM='';var CCTM='';var CCNM='';var CRCL=''; var CRL='';var OCO='';var DST='';var LA='';var CEM='';var CES='';var STB='';var SSB='';var SES='';var SEM='';var SRS='';var SCS ='';var RES='';
//*************************************************//
//Adding Notes & Attachments
var LA='0';
//Custom Email Subject
var CES='Re: Agreement for On-Site Mobile Services from TestCompany, Inc.:';
//Custom Email Message
var CEM='{!JSENCODE(Account.Name)}\\n{!Contact.Name}\\n{!JSENCODE(Contact.MailingStreet)}\\n{!Contact.MailingCity}, {!Contact.MailingState} {!Contact.MailingPostalCode}\\n\\nRe: Agreement for On-Site Mobile Services\\n\\nPlease find attached our Agreement for Services (agreement) for {!Opportunity.Account}. The Agreement outlines the services to be provided by TestCompany, fee schedule and our general terms and conditions for your review and electronic signature.\\n\\nOn behalf of TestCompany, we look forward to the opportunity to serve your organization.\\n\\n{!Opportunity.OwnerFullName}\\n{!Opportunity.OwnerTitle}\\nexaminetics\\n{!Opportunity.Owner_Street_Address__c}\\n{!Opportunity.Owner_Address__c}\\n{!Opportunity.OwnerPhone}\\n{!Opportunity.OwnerEmail}\\nwww.testcompany.com';
//********* Page Callout (Do not modify) *********//
window.location.href ="/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Opportunity.Id}&RC="+RC+"&RSL="+RSL+"&RSRO="+RSRO+"&RROS="+RROS+"&CCRM="+CCRM+"&CCTM="+CCTM+"&CRCL="+CRCL+"&CRL="+CRL+"&OCO="+OCO+"&DST="+DST+"&CCNM="+CCNM+"&LA="+LA+"&CEM="+CEM+"&CES="+CES+"&SRS="+SRS+"&STB="+STB+"&SSB="+SSB+"&SES="+SES+"&SEM="+SEM+"&SRS="+SRS+"&SCS="+SCS+"&RES="+RES;
//*******************************************//
Ampersands are characters outside the ASCII set. Since the custom button logic is pushing this data through a URL, try URLENCODING in addition to JSENCODE.
Example:
CEM="{!URLENCODE(JSENCODE(Account.Name))}
I would recommend applying this for all your merge fields.

Thunderbird Addon - Filter by Sender

I have a list of email ids.i want to filter inbox messages and display only emails from those users in thunderbird. Please help me doing this.
This is what i tried so far and it's not working.But im getting completely irrelevant error message "We are unable to print or preview this page".
var gLocalIncomingServer = MailServices.accounts.localFoldersServer;
var gLocalMsgAccount = MailServices.accounts.FindAccountForServer(
gLocalIncomingServer);
var gLocalRootFolder = gLocalIncomingServer.rootMsgFolder
.QueryInterface(Ci.nsIMsgLocalMailFolder);
const kInboxFlag = Components.interfaces.nsMsgFolderFlags.Inbox;
var gLocalInboxFolder = gLocalRootFolder.getFolderWithFlags(kInboxFlag);
gLocalRootFolder.findSubFolder(gLocalInboxFolder.URI);
gLocalInboxFolder.setFlag(Ci.nsMsgFolderFlags.Mail);
// Force an initialization of the Inbox folder database.
var folderName = gLocalInboxFolder.prettiestName;
var aValue = "example#domain.com";
var aAttrib = Ci.nsMsgSearchAttrib.Sender;
var aop = nsMsgSearchOp.Contains;;
var hitCount = 1;
var searchListener =
{
onSearchHit: function(dbHdr, folder) { hitCount++; },
onSearchDone: function(status)
{
print("Finished search does " + aHitCount + " equal " + hitCount + "?");
searchSession = null;
do_check_eq(aHitCount, hitCount);
if (onDone)
onDone();
},
onNewSearch: function() {hitCount = 0;}
};
// define and initiate the search session
var hitCount;
var searchSession = Cc["#mozilla.org/messenger/searchSession;1"]
.createInstance(Ci.nsIMsgSearchSession);
searchSession.addScopeTerm(Ci.nsMsgSearchScope.offlineMail, gLocalInboxFolder);
var searchTerm = searchSession.createTerm();
searchTerm.attrib = aAttrib;
var value = searchTerm.value;
// This is tricky - value.attrib must be set before actual values
value.attrib = aAttrib;
value.str = aValue;
searchTerm.value = value;
if (aAttrib > nsMsgSearchAttrib.OtherHeader)
searchTerm.arbitraryHeader = gArrayHdrs[aAttrib - 1 - nsMsgSearchAttrib.OtherHeader];
searchTerm.op = aOp;
searchTerm.booleanAnd = false;
searchSession.appendTerm(searchTerm);
searchSession.registerListener(searchListener);
searchSession.search(null);
alert("search is done:");
Have you seen this Mozilla page? How do I search for a particular contact property (name, email)?
You don't really need to write any JS code to accomplish this. Thunderbird's search mechanism can be used in two UI-accessible ways:
Define a "saved search" folder. This filters one or more folders with a set of criteria and presents the results in a single folder. See and be aware you probably want an offline search since it will be faster than asking the IMAP server: http://kb.mozillazine.org/Saved_Search
Define a "mail view" that can be applied to any folder. Customize the mail toolbar by right clicking on it, choosing "customize..." and dragging the combo-box labeled "Mail Views" to the toolbar. Close the customize dialog by hitting "Done". Click on the combo-box on the toolbar, choose "customize...", hit "new..." to define and name your filter criteria. You can then apply the mail view by clicking on the combo box and locating it under the "Custom Views" header.
For your filter criteria, you can either type in all the names as separate predicates where "any" rule matches, or you might want to use the "is in my address book" predicate and just put all of those people in a special address book. For example, such a rule would look like: "From" "is in my address book" "cool people". You can create a new address book via "File... New... Address Book" from the Address Book window.
If you prefer to do things programatically and you want to be able to have the list of people vary at runtime, you will want to check out my blog post on creating quick filter bar extensions, as that's the easiest way to hook custom filtering logic into the Thunderbird UI that won't break:
http://www.visophyte.org/blog/2010/05/02/thunderbird-quick-filter-bar-extensions-theyre-a-thing/
Code for that example currently lives here on github:
github.com/asutherland/qfb-pivot
If your list of e-mails isn't going to change a lot, you can also create the "saved search folders" (virtual folders, internally), you should check out mxr.mozilla.org/comm-central/source/mailnews/base/src/virtualFolderWrapper.js and its createNewVirtualFolder method.
Apologies for de-hyperlinking two of the URLs, but the anti-spam mechanism won't let me have more than 2 links in the post...

Categories

Resources