In CRM 2011, using javascript, how can I get the calling entity or form type name? - dynamics-crm-2011

In CRM 2011, using JavaScript, how can I get the calling entity or form type name? For example, if I open an activity, I want to see if I opened this activity from an account form or a contact form etc. I have googled this and I am not finding anything.

In that particular case you should check the regarding field - CRM automatically populates this, that should contain the information you require.

Use
window.parent.opener.Xrm.Page.data.entity.getEntityName()
This will only work if you have opened up the entity from the calling entities' form.
It will not work if you open up the entity from the related activities section by on the left.
Basically the parent page should have the entity form loaded in order to use the Xrm.Page.data object.

Related

How to store multiple images for an entity record in Dynamics CRM 2013?

Microsoft Dynamics CRM 2013 can store exactly one image per entity record. Storing multiple images per record seems to be not intended, since you get an error message if you try to add more than one entity field of type image. However, I need to store multiple images per record, so is there a way to achieve this? Some workaround maybe?
It depends on whether you need to see the photo you're attaching to the CRM record instantly or not. IE Does it just needs to be referenced in the same way other attachments (such as documents) are referenced?
If you do not need to see the multiple photos from the record without downloading first and you're happy to reference them in the same way that you reference other attachments, you could add the additional photos in the Notes area of the record, or if you need classifications against those photos, create a new entity to hold photos and Categorise them using an Option Set.
The alternative, if you do need to see the photos instantly when viewing the record, is to either write some custom code and utilise the iFrame feature of the entity form which looks at a custom entity holding photos behind the scenes, or to look at an existing product such as PowerPhoto.
As a possible workaround you can try to use Annotation entity.

How to add value to a field from another lookup field?

I have a custom entity Partnership in which I have one lookup field contacts.
now I want to add the name field value of the partnership from contact fullname in time of creation of Partnership.
is it possible with the help of pre-existing configuration settings,(without plugin or web resource)
Thanks.
Without using a plug-in or web resource you have a couple options.
1- You can configure the mappings between the 2 entities by going to the Entity (contact) -> Relationship -> Mappings -> and add a new mapping there. For this to work though, you will need to create the child record from the subgrid of the contact, and if the contact changes it won't update the values. So it may or may not be an ideal solution for you.
2- You can create a workflow rule that runs on create and/or update of the Partnership record that pulls the value from the parent contact onto the partnership record. The downside of this is that workflows are async so you won't see the update for a few seconds and refresh the Partner record.
Hope this helps.
If you want to be able to click the "New Partnership" button in the CRM ribbon, then select a contact, and have the name of the contact, be used to populate another field on the form, you will have to use JavaScript. There is no configurable way of doing it.
If you'd like the value to be populated before it is saved in the CRM database, you could use JavaScript, or a custom Plugin. If you'd like the value to be updated after the record is created, you could use a workflow.
You'll have to use one of those three methods to populate the field. The real question I have though, is why are you bothering to populate the field in the first place? You can add the full Contact name to any view, so I don't see a real big reason to include it.

Remove note's autosave functionality by adding other entity's notes on form in CRM 2011

In CRM 2011, notes get automatically created and attached to main record on lost focus event. Requirement is to remove this auto save functionality. Only till main form is open user should be able to edit notes. And newly added notes should only get saved once main form is saved. For example, if user add one note and closes the browser or do not save the main form, then that note should not get attached to main record, new note should get discarded.
I was thinking following solution:
create new custom entity TempNotesHolder
Create 1:N relationship with the entity where we want this functionality, for example Case entity
Make actual case's note section read only(it is requirement, user don't want to edit/delete functionality for notes once note get created)
Write plugin for create event of Case and create one Record for TempNotesHolder and associate it with case(RegardingId field in TempNotesHolder = incidentId) This will ensure one Case will always have only one associated TempNotesHolder record. There is no way in CRM 2011 to ensure One entity record will have only one record in associated entity i.e. 1:1 relationship. At least I don't know the way. Let me know if any one are aware about it.
On Case form, add one IFrame below Case's note section
on case form load event, get TempNotesHolderId associated with case using fetchXml.(There is no actual field in Case entity that refer to associated TempNotesHolder, hence need to use fetchXml. Some how we can add associated TempNotesHolderId to Case entity, and place that field on Case form, make it hidden, to avoid fetchXml)
Prepare url to display only notes of TempNotesHolder record.(/_controls/notes/notesdata.aspx?EnableInlineEdit=false&EnableInsert=true&id=&ParentEntity=
Set this url to newly added IFrame, so notes of associated TempNotesHolder get displayed in IFrame. It will also have link "Add New Note".
User can add note to TempNotesHolder which are not directly added to Case record.
Next develop plugin on pre save event of Case and check if there are any notes added to TempNoteHolder, if yes move those notes to Case record, and delete notes for TempNoteHolderId. This way notes will get saved to main record only on main form save.
To handle browser close event after adding few notes to TempNotesHolder, write plugin on Case pre Retrieve event, check if any notes present for associated TempNotesHolderId, if present then delete those notes. (As notes are present on TempNotesHolderId, that means due to some reason these notes are not moved to actual case record and we no longer need them, so delete them. This will ensure on case load, TempNotesHolder note section always be blank)
The above solution was fine till step 8. When I tried to add notes in TempNotesHolder, it gave me error, "Record with does not exists in TempNotesHolder". Then I checked that GUID, I disappointed to know CRM is taking IncidentId when I create note for TempNotesHolder. Then I tracked down the actual code for create notes to find why it is taking IncidentId instead of TempNotesHolderId. I found following code in "_static/_controls/notes/notes.htc" function name "UpdateNote"
xml="0"+CrmEncodeDecode.CrmXmlEncode(value)+""+_parentCrmFormSubmit.crmFormSubmitId.value+""+this.parentEntityType+""+CrmEncodeDecode.CrmXmlEncode(currentTitle)+""+this.userId+""
CRM is taking _parentCrmFormSubmit.crmFormSubmitId.value as objectid while creating note.
Now I stuck with this problem. Any thoughts to overcome this show stopper issue are appreciated. Also any other alternate solution to main requirement are also welcome.
Pravin Pujari (Microsoft Dynamics CRM 2011 Developer)
I would suggest simplifying the solution as follows:
Add a field to Case called new_notetext.
Create a Plugin against the Pre-Create and Pre-Update messages on the Case entity.
In the plugin, take anything entered into new_notetext and add a note to the Case entity using that text. Then clear the field new_notetext so nothing is saved with the record.
Should work just fine and is much simpler to implement.

crm 2011 switch between multiple forms within single entity

We currently design our solutions using a single form per entity. We have a current set of requirements where the 10 or so entities are similar in terms of functionality and data collection. Ideally we would like to have entity with 10 or so forms and dependent on a lookup value display the correct form on the click of a custom button.
I have previously worked with a supplier who implemented something like this displaying the correct form using the GUID (using the formid querystring parameter) on the load event using JavaScript. Although this worked 95% of the time, depending on the client machine it occassionally did not load the correct form due to timing issues i.e. the code had not properly executed by the time the form loaded.
Is there a best practice for using this kind of technique?
I guess my other options are
1) multiple entities
2) one form with tabs/sections that i show/hide on the form load
I am leaning towards implementing option 2)
Richard
The multiple forms inside of CRM 2011 is only for different roles. It is not designed to handle switching between forms based on entity attributes.
Granted what you are trying to do is possible, but you will encounter
issues and will need JavaScript to switch the user to the right form
type. You'll also cause the user to load the form twice each time (kind of ugly)
Another option is to use JavaScript to show/hide the proper elements
on the form (similar to 4.0)
Or you can just use multiple entities with a common JS file for any
kind of logic.
depending upon any field value you can switch the forms through JavaScript.
In JavaScript redirect page to url:
[serverurl]/main.aspx?etn=[entityname]&extraqs=etc%3d[entitytypecode]%26formid%3d[formguid]%26id%3d%257b[recordguid]%257d&pagetype=entityrecord
Where
entityname = entity name (e.g. incident),
entitytypecode=entity type code (e.g for incident it is 112),
formguid=guid of the form to which you want to redirect,
recordguid = guid of the record. If you skip id parameter, form will open in create mode.

SharePoint 2010 - Customizing the rendering and behavior of a List field

In my SharePoint List, I have an "Employee" column that is a User type field. I would like to add some custom Business Logic to the processing of this field.
Currently, when the user adds a row, I check to see if the user is an Employee or a Manager and then change the behavior on this column accordingly. I do this by statically rendering the field in my custom "ListForm Rendering Template", just before my custom ListFieldIterator. I simply use a standard SharePoint FormField (and FormLabel) control. In the markup of the FormField control, I specify the FieldName (Employee) and an event handler for the Load event. In this Load event, I will check to see if the current user is an Employee or Manager (using two different SharePoint groups). If the user is an Employee I set the value of the field to the current user (this part works perfectly). I also want to change the field so it can't be modified. I thought I might be able to just change the ControlMode on the field (in the code of the OnLoad Event Handler) to Display, but for some reason this has no effect. The field still renders with the full, people picker editor. Am I not changing the fields control mode soon enough? Or is this simply not the correct approach? The other logic I want to put in is if the user is a Manager, I would like to allow that user to select the person from a list (SharePoint group) of Employees. It may be easier to just use the people picker and limit the selectable users to that group. (I think I can do this with the SelectionGroup property.) Although, it would be better if I could just provide a dropdownlist of users, which I could possibly do with a hidden dropdownlist that I would show and event handlers that I could use (handle event selectedindexchanged) to pull the value selected and populate the (now hidden) Employee (user) field. Does this approach make sense? Assuming all that will work, the real difficulty I am having is with changing the ControlMode (rendering) on the field (when the user is an employee) to a label or some kind of read only control, which is how that field renders when viewing the row, which is why I think if I can just trick the control into thinking it is in Display mode then it should work perfectly!
I am still learning SharePoint, but I am very proficient in ASP .Net. This is why I would like to keep my customizations in this Custom Rendering Template, using code behind and leverage my existing skill set as much as properly.
Any thoughts, opinions or advice? Does anyone know why I can't get the column to switch the "Control Mode"?
I do not think that I fully understand your scenario. Some code samples could help.
But anyway it sounds like you want some heavy customizations of the user field. In that case you might want to have a look at creating a custom field with all its advantages and disadvantages. Have a look at MSDN: http://msdn.microsoft.com/en-us/library/gg132914.aspx
Another option might be - in case you do not want to re-use this column in many list definitions - that you can get away with your custom rendering template and create a custom create/edit form where you implement the specific edit behaviour for the field (plain ASP.NET with some SharePoint controls). Here is a nice walk-through on how to grab a custom edit form from SharePoint designer: http://community.bamboosolutions.com/blogs/sharepoint-2010/archive/2011/05/12/sharepoint-2010-cookbook-how-to-create-a-customized-list-edit-form-for-development-in-visual-studio-2010.aspx
I hope this helps. Kr., Bernd.

Resources