English 中文(简体)
Setting BusinessEntity picklist value using CRM 4.0 webservice
原标题:

I m trying to create an ImportMap object in CRM 4.0. I need to set the TargetEntity property which is a Picklist value. link text seems to imply that it can be done by using

importmap map = new importmap();
map.name = "test map";
map.targetentity = new Picklist();
map.targetentity.name = "Contact"

but this always seems to leave the target entity property as null.

Any thoughts?

最佳回答

If its a pick list, you will have to provide the index value. Assuming that you have an enum called TargetValues.Contact having value 1, then it would go like:

map.targetentity = new Picklist();
//map.targetentity.name = "Contact"
map.targetentity.Value = Convert.ToInt32(TargetEntities.Contact);

-- Edit --

I believe for what you are trying to achieve you will have to somehow retrieve the target entity and only then you will be able to enumerate them.

See this, probably this would help.

If above is of no use, then following is how you can do it:

  1. Opened picklist, from the UI, write down the number of indices and their cooresponding values.
  2. Created an enum in code, and assign those values/indices to it.
  3. Use enum at runtime(given in example above), to set the picklist.

But then somehow indices may change over a period of time, so in that case you can create an enumerated xml with those values/indices, and load them on runtime. But the problem with this approach is that:

  1. Everytime anyone is going to change the index, which is very rare, the administrator shall also have to change the xml file.
  2. Load an external xml file is an overhead.

Not-so-good approach, but running against a ticking deadline this is what you can do; this is never going to break or cause trouble. Just that xml loading part is not good.

Btw, if you would go through the CRM SDK, you will find the examples of similar sort.

问题回答

Take this function to dynamic request picklist values:

public IDictionary<int,string> PickListValues(string entityname, string attributename)
{
    var req = new RetrieveAttributeRequest();
    req.EntityLogicalName = entityname;
    req.LogicalName = attributename;
    req.RetrieveAsIfPublished = true;

    var response = (RetrieveAttributeResponse)Service.MetaDataService.Execute(req);

    var picklist = (PicklistAttributeMetadata)response.AttributeMetadata;

    var res = new Dictionary<int,string>();

    foreach (var item in picklist.Options)
       res.Add(item.Value.Value, item.Label.UserLocLabel.Label);

    return res;
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签