Default the "Look for" field in a lookup view - dynamics-crm-2011

If the "look for" drop down contains more than one item (e.g. Account, Contact) is it possible to set the default option (in my scenario to the second option Contact)?

In CRM 2015 you can use the following if you want to filter the lookup so it contains only contacts
// Filter the dropdown of the lookup so that it only contains contacts + do not allow accounts ,in the contact views, visible when the user clicks more records
var noAccountsfilter = "<filter type='and'><condition attribute='statecode' operator='ne' value='0' /></filter>";
Xrm.Page.getControl("parentcustomerid").addCustomFilter(noAccountsfilter, 'account');

function Form_OnLoad()
...
preFilterLookup();
..
}
function preFilterLookup() {
Xrm.Page.getControl("customerid").addPreSearch(addLookupFilter);
}
function addLookupFilter() {
document.getElementById("customerid_i").setAttribute ("lookuptypenames", "contact:2:Contact");
document.getElementById("customerid_i").setAttribute("lookuptypes", "2");
}
How do I change the default quick form for the CustomerId field in Dynamics CRM 2013?

Related

How to get source list types of particular list/record field?

Here is I have two entity custom fields with list/record type,
custom_dev_j15 entity field has a custom source list (eg: one, two, three, four, etc)
custom_qa_v93 entity field has a standard source list as an object (eg: customer )
I've two vendor entity custom fields as stated in screenshots of question,
custentity473 --> customer is selected as list source
custentity474 --> custom_dev_j15_m_list as selected as list source ( which is custom list)
Here is snippet that i used to get the options of these fields,
// Snippet
var fieldDetails = {};
var record = nlapiCreateRecord("Vendor");
var field = record.getField("custentity473");
var selectoptions = field.getSelectOptions();
for ( var i in selectOptions) {
var Option = {
id : selectOptions[i].getId(),
label : selectOptions[i].getText()
}
Options.push(Option);
}
fieldDetail["options"] = Options;
But my need is to get source list information like name of the list source (customer or custom_dev_j15_m_list) via suitescript
any idea on how to get this information?
Thanks in advance
I'm not sure I understand this question for what you're trying to do.
In NetSuite almost always, you accommodate to the source list types because you know that's the type, and if you need something else (e.g. a selection which is a combination/or custom selection you'll use a scripted field)
Perhaps you can expand on your use case, and then we can help you further?

Access List Options for a Field in a Custom Table in Kentico 10

I have a custom table with a few fields that have list options for the user to select from when adding the content. Is there something in the API that allows me to access the options for a particular field so I can use those same options in a filtering widget?
Something like the below but that works for fields in a custom table?
var guids = ParentDocument.GetValue("CustomFieldName").Split(';');
var referencedDocs = DocumentHelper.GetDocuments().WhereIn("DocumentGuid", guids);
UPDATE - The code in case the link in the answer changes:
protected string[] GetFormFieldOptions()
{
DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo("custom.MyPageTypeName");
if (dci != null)
{
//Get the data from the form field
FormInfo fi = new FormInfo(dci.ClassFormDefinition);
FormFieldInfo ffi = fi.GetFormField("Industry");
string[] industries = ffi.Settings["Options"].ToString().Split('\n');
return industries;
}
return null;
}
Use DataClassInfoProvider in order to get data you need. Check this blog post to see more details.
You can use the same code as you have in your question. The difference is you need to get 2 different things which are not available at the "Page" or "Document" level:
Custom table object
Custom table item based on #1
You use the API to get the custom table item:
var cti = CustomTableItemProvider.GetItem(<id or guid>, "yourcustom.tableclassname);
if (cti != null)
{
string[] s = ValidationHelper.GetString(cti.GetValue("YourField"), "").Split(";");
}
Update
To get a dynamic list of options in a field you can simply use a listing control like a dropdown list or a radio button list as your control (vs. a textbox). Then in the properties for the dropdownlist, you can set it to a query. In the query enter something like
-- if you wan to have a 'select one' add this
SELECT '', '-- select one --'
UNION
SELECT ItemID, FieldName
FROM CustomTable_Name
ORDER BY 2

How to set the "Ship To Select" shipping address dropdown field for a Sales Order?

When creating a Sales Order in NetSuite via Suitescript, we can successfully set the "Ship To" (Field ID: shipaddress) by sending it a string containing a full address.
This causes a problem because the "SHIP TO SELECT" dropdown field retains the default address set on the customer.
Ideally we would rather send in the valid ID from the Customer record and set the dropdown "SHIP TO SELECT" (Field ID: shipaddresslist) field using that ID.
We can get the valid ID, but cannot find a way to set that ID on the field in order to populate that dropdown.
Generally if you do this outside the context of a User Event Before Submit script you also need to make sure you save with sourcing.
var soRec = nlapiLoadRecord('salesorder' soId);
soRec.setFieldValue('shipaddresslist', addressId);
nlapiSubmitRecord(soRec, true);
// alternatively nlapiSubmitRecord(soRec, {enablesourcing:true [, disabletriggers:true|false, ignoremandatoryfields:true|false]});
If you are still seeing the old address text you might add:
soRec.setFieldValue('shipaddress', null);
before submitting.
If what you want to do is set a custom address then similar but you need to set the override:
var soRec = nlapiLoadRecord('salesorder' soId);
soRec.setFieldValue('shipaddresslist', null);
soRec.setFieldValue('shipoverride', 'T');
soRec.setFieldValue('shipaddress', formattedAddressString);
nlapiSubmitRecord(soRec);
Be warned though that doing this will make any searches or automation that rely on address fields miss or produce incorrect results around this record.
If you want a custom address you are generally better off:
var soRec = nlapiLoadRecord('salesorder' soId);
soRec.setFieldValue('shipaddresslist', null);
soRec.setFieldValue('shipaddr1', '123 Elm St.');
soRec.setFieldValue('shipcity', 'Portland');
...
nlapiSubmitRecord(soRec);

Sharepoint webpart combobox of lists

I have a webpart that works off of a list but what I'm trying to do create a dropdown that contains a list of sharepoint lists so that when the user edits the page and selects 'modify shared webpart' they are able to choose a list item and that gets parsed back to the webpart.
Any examples or links to examples appreciated!
Thanks
Dan
What you are looking for is called a Toolpart. Take a look at this example for a tutorial on how to create one.
Overall, your general steps will be:
Create your custom Toolpart class inheriting from Microsoft.SharePoint.WebPartPages.ToolPart
In your custom Toolpart, override CreateChildControls, write the code to iterate over the lists in your SPWeb, and add those to a DropDownList
In your webpart, override GetToolParts and add your custom ToolPart so that it shows up in the right hand side
It sounds like you want to create a custom editor part. In the part you would have one dropdown that shows the names of the lists (you probably want to filter hidden and empty lists) and, when an item is selected from the list, a second dropdown shows the Title column of the items from the selected list.
Here's some code (edited here, so it will need to be cleaned up) to help you get started:
protected Page_Load(...)
{
if (IsPostBack) return;
var web = SPContext.Current.Web;
var query = from list in web.Lists
where list.Hidden == false && list.ItemCount == 0
select list;
DropDownList1.DataSource = query;
DropDownList1.DataTextField = "Title";
DropDownList1.DataBind();
}
protected DropDownList1_SelectedIndexChanged(...)
{
var web = SPContext.Current.Web;
var listName = DropDownList1.Text;
var list = web.Lists[listName];
var table = list.Items.GetDataTable();
DropDownList2.DataSource = table;
DropDownList2.DataTextField = "Title";
DropDownList2.DataValueField = "ID";
DropDownList2.DataBind();
}

Can a SharePoint list item have it's Targeted Audience calculated or otherwise automatically specified?

I want to show targeted (filtered) content from a list to users. I already have a column in the list that basically has the Target Audience value. This field is a multi-choice column (checkbox input) which I prefer over the current input field for Targeted Audiences.
To get audience filtering to work I unfortunately need to have the Targeted Audience field filled out for every list item. My current plan is to use a simple SharePoint designer workflow to set the Targeted Audiences field based on my other field, but I'm wondering if there is a better way. Am I just looking at this wrong?
Note that I know audiences can also be used to hide/show web parts, but that is not something I am interested in.
You could try and give this a whirl...
SPField audienceField = null;
try
{
audienceField = list.Fields[Microsoft.SharePoint.Publishing.FieldId.AudienceTargeting]
}
catch
{}
if(audienceField != null)
{
try
{
Audience siteAudience;
ServerContext context = ServerContext.GetContext(site);
AudienceManager audManager = new AudienceManager(context);
foreach (SPListItem item in list.Items)
{
string audienceName = item["fakeAudienceField"]; //should be the audience name created in SSP
siteAudience = audManager.GetAudience(audienceName);
Guid id = siteAudience.AudienceID;
item["Target Audiences"] = id.ToString()+";;;;";
item.Update();
}
}
catch
{}
I do not believe Target Audiences can be set up as a calculated field, in which case your options are workflow or a list item event receiver.
To set the audience field value, you can use AudienceManager.GetAudienceIDsAsText; Gary Lapointe has a post with example usage.
Maybe use a webpart to display the content of the list and use Audiences on the webpart sounds a solution easier to manage...

Resources