Get CustomProperty value of taxonomy - c#

I assigned Custom property to Taxonomy.I need to get the custom property value by passing Taxonomy Id by using programmaticaly with Ektron Framework Api.
I worked in Ektron 9.
Thanks in advance!

You can retrieve Taxonomy Custom properties by using the CustomPropertyObject class. I use a code similar to this one:
var customApi = new CustomPropertyObject();
var customPropertyId = 0; // Put here your custom property id
var taxonomyId = 0; // Put here your taxonomy Id
var customProperties = customApi.GetItem(taxonomyId, 2057 /* language code */,
EkEnumeration.CustomPropertyObjectType.TaxonomyNode, customPropertyId)
.Items.ToDictionary(i => i.PropertyId, i => i.PropertyValue.ToString());
You just need to put your own TaxonomyId, CustomPropertyID and language code.
Hope this helps,
Jonatan

Related

Creating Item in SP List oDat.Type for People attribute

I need to create an item with Person/People field.
I am able to populate fields like Title, DateTime, TextField as seen below, but I am not able to populate Person field at all.
I have tried sending Display Name, User ID and UPN.
var fieldValueSet = new FieldValueSet();
fieldValueSet.AdditionalData = new Dictionary<string, object>();
fieldValueSet.AdditionalData.Add("Title#odata.type", "Edm.String");
fieldValueSet.AdditionalData.Add("Title", task.Title);
fieldValueSet.AdditionalData.Add("Plan#odata.type", "Edm.String");
fieldValueSet.AdditionalData.Add("Plan", plan.Title);
fieldValueSet.AdditionalData.Add("Assigned#odata.type", "Edm.String");
fieldValueSet.AdditionalData.Add("Assigned", assignee.UserPrincipalName);
fieldValueSet.AdditionalData.Add("DueDate#odata.type", "Edm.String");
fieldValueSet.AdditionalData.Add("DueDate", task.DueDateTime);
var listItem = new ListItem
{
Fields = fieldValueSet
};
await graphServiceClient.Sites["SPURL:/sites/ITOddeleni:"].Lists["ListName"].Items
.Request()
.AddAsync(listItem)
Does your user principal name look like an email? (e.g. some.person#yourtenant.onmicrosoft.com). If that is the case then you should probably try to convert it to a sharepoint-claim version: i:0#.f|membership|some.dude#yourtenant.onmicrosoft.com.
If you have an authenticated ClientContext in your app, then you could resolve the username by calling the SharePoint utility:
Utility.ResolvePrincipal(context, context.Web, userEmail, PrincipalType.User, PrincipalSource.All, null, true);
If you don't have a context then you can try and combine strings (not as robust, but should work as well).
This answer suggests that you should try and set the LookupId value for the field (sorta the same way you set user values using the SharePoint's REST api):
var assigneeLookupId = // Get the assignee's user id on the site (wssid)
fieldValueSet.AdditionalData.Add("AssignedLookupId#odata.type", "Edm.Int32");
fieldValueSet.AdditionalData.Add("AssignedLookupId", assigneeLookupId);
The following schema would allow you to insert multiple person values:
SOLUTION
After help from comments i got this answer which worked
{
"AssignedLookupId#odata.type" : "Collection(Edm.Int32)"
"AssignedLookupId": [1,2,3]
}
This approach is in line with the way MS Graph returns values for Lookup fields.

SharePoint Online CSOM Site Column Default Value

In SharePoint Online, I'm having problems setting a site Managed Metadata column default value using CSOM (C#). For brevity, I've not included exception handling in my code. Here's what I have:
// Code snippet for what I'm trying to achieve
using (ClientContext ctx = NewCtx(SiteInfo.Url)) // NewCtx is just a static member I use to return a ClientContext object
{
Field taxColumn = (Field)ctx.Web.Fields.GetByTitle("myMMColumnName");
ctx.Load(taxColumn);
ctx.ExecuteQuery();
TaxonomyFieldValue termField = new TaxonomyFieldValue();
termField.Label = "My MM Term";
termField.TermGuid = "b269aef7-6f47-4b02-bf80-7edfb7166a30";
termField.WssId = -1;
taxColumn.DefaultValue = value;
// Place holder for added code (see below)
taxColumn.Update();
ctx.Load(taxColumn);
ctx.ExecuteQuery();
}
The value appears in the UI under Site Columns, but no associated item is created in the TaxonomyHiddenList, which makes sense because setting the lookup WssId to "-1" doesn't resolve and therefore, the default value doesn't have a lookup and appears empty in the list- and library-level column.
The closest resolution I found was an article (albeit not CSOM and linked below) suggested creating a "dummy" list item (against a list that was consuming the MM column). This would trigger the creation of the item in the TaxonomyHiddenList but the article suggests not committing the "dummy" item creation. I've tried this too, but seems to have no effect. This is the code I added to the place holder mentioned in the previous code block:
List myList = ctx.Web.Lists.GetByTitle("My List");
ctx.Load(myList);
ctx.ExecuteQuery();
TaxonomyField taxField = ctx.CastTo<TaxonomyField>(myList.Fields.GetByTitle("myMMColumnName"));
ListItemCreationInformation newItemInfo = new ListItemCreationInformation();
ListItem newItem = myList.AddItem(newItemInfo);
newItem["myMMColumnName"] = termField;
taxField.SetFieldValueByValue(newItem, termField);
The article uses the .SetFieldValue method, which isn't available in CSOM so I may well have assumed incorrectly that .SetFieldValueByValue is comparable.
Thanks for reading!
References:
Article - http://sharepointificate.blogspot.com/2014/04/setting-managed-metadata-column-default.html
SetFieldValue Method belongs to TaxonomyField class, it means the line:
Field taxColumn = (Field)ctx.Web.Fields.GetByTitle(taxFieldTitle);
needs to be replaced with:
var taxColumn = ctx.CastTo<TaxonomyField>(ctx.Web.Fields.GetByTitle(taxFieldTitle));
or
TaxonomyField taxColumn = ctx.CastTo<TaxonomyField>(ctx.Web.Fields.GetByTitle(taxFieldTitle));
Once TaxonomyField is initialized, the default value could be set as shown below:
//get taxonomy field
var taxColumn = ctx.CastTo<TaxonomyField>(ctx.Web.Fields.GetByTitle(taxFieldTitle));
ctx.Load(taxColumn);
ctx.ExecuteQuery();
//initialize taxonomy field value
var defaultValue = new TaxonomyFieldValue();
defaultValue.WssId = -1;
defaultValue.Label = termLabel;
defaultValue.TermGuid = termId.ToString();
//retrieve validated taxonomy field value
var validatedValue = taxColumn.GetValidatedString(defaultValue);
ctx.ExecuteQuery();
//set default value for a taxonomy field
taxColumn.DefaultValue = validatedValue.Value;
taxColumn.Update();
ctx.ExecuteQuery();
Note: TaxonomyField.GetValidatedString method is utilized for
validation of taxonomy field value which in turn includes the
resolving of WssId value
Update
Use Field.UpdateAndPushChanges method to propagate changesto all lists that use the field
So, replace:
taxColumn.Update();
ctx.ExecuteQuery();
with:
taxColumn.UpdateAndPushChanges(true);
ctx.ExecuteQuery();

get the description field of a sitefinity classification in code

I am new to sitefinity, I am looking for a way to the access the description field of the classification in my code.
Please let me know how I can do that.
I have written code that gets me all the classifications(hierarchial taxonomy) in the form of a tree that I am binding to a RadTreeView control.
Each node in the RadTreeView control has properties like text, navigateURL etc. but no Description. I assume I have to do it differently to get the description field.
Any help or direction is appreciated. It looks to me like a very basic implementation to get the description but not able to get it.
Thanks!
Below is a function that uses the Sitefinity API to look up a Category by Title.
You'll need the following using statements:
using Telerik.Sitefinity.Taxonomies;
using Telerik.Sitefinity.Taxonomies.Model;
I've added the line that gets the description to hopefully better answer your question.
private Taxon GetCategoryByTitle(string category)
{
var manager = TaxonomyManager.GetManager();
var categoriesTaxa = manager.GetTaxonomy<HierarchicalTaxonomy>(TaxonomyManager.CategoriesTaxonomyId);
var taxomony = categoriesTaxa.Taxa.FirstOrDefault(t => t.Title == category);
var description = taxomony.Description; //get description here
return taxomony;
}

How do I retrieve simple products associated with configurable products

Hi i'm using magento soap api v2 with c#. Do far I have been calling
var groupedProducts = magentoService.catalogProductLinkList(sessionId, "grouped", id, "productId");
that does return grouped Products, but instead I would like to retrieve simple products such as green large t-shirt which is associated with configurable t-shirt.
How can this be achieved?
Unfortunatelly that's not possible with the magento SOAP api. You are not able to retrieve child products of a parent product via the api. Believe me, I have tackled this myself some time ago. I can suggest 2 fixes and 1 workaround.
Workaround - Try to retrieve child products by sku or name. This can work provided that all your child products use the parent's name or sku as the prefix. That's how I resolved it in the beginning and it worked well as long as the client did not introduce child product names that did not match the parent name. Here's some sample code:
//fetch configurable products
filters filter = new filters();
filter.filter = new associativeEntity[1];
filter.filter[0] = new associativeEntity();
filter.filter[0].key = "type_id";
filter.filter[0].value = "configurable";
//get all configurable products
var configurableProducts = service.catalogProductList(sessionID, filter, storeView);
foreach (var parent in configurableProducts)
{
filters filter = new filters();
filter.filter = new associativeEntity[1];
filter.filter[0] = new associativeEntity();
filter.filter[0].key = "type_id";
filter.filter[0].value = "configurable";
filter.complex_filter = new complexFilter[1];
filter.complex_filter[0] = new complexFilter();
filter.complex_filter[0].key = "sku";
filter.complex_filter[0].value = new associativeEntity() { key="LIKE", value=parent.sku + "%" };
var simpleProducts = service.catalogProductList(sessionID, filter, storeView);
//do whatever you need with the simple products
}
Fix #1 - Free - Write your own api extension. To retrieve child products you could use:
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
You then send the results to the api caller and all should be well. I have not tried that myself, though, so I'm not sure if there are any other problems on the way.
Fix #2 - Paid - Get the (excellent, but pricey) CoreAPI extension from netzkollektiv. That's what I did when the workaround stopped working out for me and never regretted this decision.
I dont think what you are trying to do is possible with default magento SOAP api.
What you could do is create a custom api
eg.
How to setup custom api for Magento with SOAP V2?
http://www.magentocommerce.com/api/soap/create_your_own_api.html
Then create the logic to retrieve all the simple products associated with that configurable product.
$_product = Mage::getModel('catalog/product')->load($id);
// check if it's a configurable product
if($_product->isConfigurable()){
//load simple product ids
$ids = $_product->getTypeInstance()->getUsedProductIds();
OR
$ids = Mage::getResourceModel('catalog/product_type_configurable')->load($_product);
}
Please be aware that it should be
... new associativeEntity() { key="like", ...
and not
... new associativeEntity() { key="LIKE", ....
Upper case LIKE does not work.
I found a Magento Extension on Github, which includes this functionallity.
Get configurable's subproducts informations in the same response.
https://github.com/Yameveo/Yameveo_ProductInfo

How to bind a .net dropdown list to a CRM 2011 Option Set

I'm sure this is possible, I just haven't got the foggiest how or where to start.
So, I have an option set created in MS Dynamic CRM which gives me a list of countries, MyCountryOptionSet. Lovely.
However, I have a number of other .net, c# applications where users can enter free text. This is not so lovely.
As such, I would like to tie these down so only countries in present in MyCountryOptionSet can be used.
Therefore, I would like to bind the countries from MyCountryOptionSet to a drop down list in my .net applications.
How would I go about doing this?
Look into RetrieveAttributeRequest and IOrganizationService. This will allow you to get the countries defined in your option set. By casting the AttributeMetadata property on the response to PicklistAttributeMetadata.
The binding to controls will be UI technology specific so post more info.
use the crm apis to get option values as follows...
_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,
serverConfig.Credentials, serverConfig.DeviceCredentials);
_serviceProxy.EnableProxyTypes();
_service = _serviceProxy;
RetrieveAttributeRequest retrieveAttributeRequest =
new RetrieveAttributeRequest
{
EntityLogicalName = EntityLogicalName,
LogicalName = optionSetLogicalName,
RetrieveAsIfPublished = true,
};
// Execute the request.
RetrieveAttributeResponse retrieveAttributeResponse =
(RetrieveAttributeResponse)_service.Execute(
retrieveAttributeRequest);
// Access the retrieved attribute.
PicklistAttributeMetadata retrievedPicklistAttributeMetadata =
(PicklistAttributeMetadata)
retrieveAttributeResponse.AttributeMetadata;
// Get the current options list for the retrieved attribute.
OptionMetadata[] optionList =
retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
//Dictionary<int,string> LocalizedLabelDic = new Dictionary<int,string>();
List<ListItem> OptionSetItems = new List<ListItem>();
foreach (OptionMetadata o in optionList)
{
OptionSetItems.Add(new ListItem(o.Label.LocalizedLabels.FirstOrDefault(e => e.LanguageCode == 1033).Label.ToString(), o.Value.Value.ToString()));
}
then bind the listitem generic collectoin to ur asp.net drop down
You can query the CRM database directly for the values using a query like this:
select Value, AttributeName
from StringMap
where AttributeName = 'New_MySet' --schema name of the global option set
and ObjectTypeCode = 1 --changes based on entity type field is associated with
Once you have the results you can bind them to the list in your application.

Categories

Resources