views:

960

answers:

1

Hi

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?

+1  A: 

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.

KMan
Thanks, that's pretty much what I figured. The problem is that this picklist I am trying to set is actually a list of all the entity types in the system, including custom ones, so I have no idea at design time what the index will be. Is there a way to dyanmically load and enumerate the picklist ? Thanks
Matt
Matt, sorry for the delayed response; please see my updated response.
KMan