Answered by:
Get parent entity id for a subgrid

Question
-
I added a new button on the ribbon for Activities on the form for Incident which opens a new Service Activity.
When I click on the button I need to open a new Service Activity and set the Regarding field to the Incident (Case) from whose form I clicked the button.
I tried with:
Xrm.Page.data.entity.getId()
but it says that entity is null.
Does anyone know how this can be done?
Thanks
Friday, September 2, 2011 4:23 PM
Answers
-
Hi Rozov,
Simply use "Mscrm.AddServiceActivityToPrimaryRecord" as the command for your newly added Ribbon Button. It will open Service Activity Record with current Case as the Regarding field.
Please let me know if you need more functionality.
Vikranth http://howto-mscrm.blogspot.com "Please Mark it as answer if it helps in resolving your query"Friday, September 2, 2011 7:47 PM
All replies
-
Hi Rozov,
Simply use "Mscrm.AddServiceActivityToPrimaryRecord" as the command for your newly added Ribbon Button. It will open Service Activity Record with current Case as the Regarding field.
Please let me know if you need more functionality.
Vikranth http://howto-mscrm.blogspot.com "Please Mark it as answer if it helps in resolving your query"Friday, September 2, 2011 7:47 PM -
Thanks for the reply. I tried this but it doesn't fire anything. I tried to google the command but I can't find anything on it. Can you show me an example page where it is used?
Thanks
Friday, September 2, 2011 11:43 PM -
I don't know how you are doing it. But I assume you are calling a javascript webresource on click of the button.
What you can do is you can pass crmparrameters to your javascript function like
<JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addExistingFromSubGridAssociated" Library="/_static/_common/scripts/RibbonActions.js">
<CrmParameter Value="PrimaryEntityTypeName"/>
<CrmParameter Value="FirstPrimaryItemId" />
</JavaScriptFunction>
the above function is using the name of the primary entity (like contact or account etc) and Id of the primary entity.
In your javascript function you pass these parameters to the form
Here is an example
The unencoded value for the extraqs parameter is ‘ownerid={B8C6E040-656E-DF11-B414-00155DB1891A}&owneridname=Mark Folkerts&owneridtype=systemuser’.
main.aspx?etn=lead&pagetype=entityrecord&extraqs=ownerid%3D%7bB8C6E040-656E-DF11-B414-00155DB1891A%7d%26owneridname%3DMark%20Folkerts%26owneridtype%3DsystemuserFor more information have a look at thisI hope this helps.
Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/- Proposed as answer by Amreek Singh Saturday, September 3, 2011 2:35 PM
Saturday, September 3, 2011 2:35 PM -
Thanks for the reply. Here is my code:
<CustomAction Id="Mscrm.SubGrid.activitypointer.NewServiceActivity" <br/>Location="Mscrm.SubGrid.activitypointer.MainTab.Management.Controls._children" Sequence="17"> <CommandUIDefinition> <Button Id="Mscrm.Subgrid.activitypointer.NewServiceActivityButton" <br/>Command="Mscrm.AddServiceActivityToPrimaryRecord" LabelText="New Service Activity" ToolTipTitle="New Service Activity" <br/>ToolTipDescription="Add new Service Activity to this Case" TemplateAlias="o1" <br/>Image16by16="/_imgs/ribbon/CustomEntity_16.png" Image32by32="/_imgs/ribbon/CustomEntity_32.png" /> </CommandUIDefinition> </CustomAction>
<CommandDefinitions> <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addExistingFromSubGridAssociated" Library="/_static/_common/scripts/RibbonActions.js"> <CrmParameter Value="Incident"/> <CrmParameter Value="FirstPrimaryItemId" /> </JavaScriptFunction> <br/><CommandDefinitions/>
How do I set the FirstPrimaryItemId and is the
FunctionName="Mscrm.GridRibbonActions.addExistingFromSubGridAssociated" Library="/_static/_common/scripts/RibbonActions.js">
an already made function that I should just use?
Thanks
- Edited by KatRiketa Tuesday, September 6, 2011 3:19 PM
Tuesday, September 6, 2011 3:18 PM -
Hi,I had to to something very similar recently.The way I did it was to first add the RibbonActions.js file as a webresource in the CRM Solution and then refer to it in the Library attribute of the JavaScriptFunction node.Something like this:<JavaScriptFunction FunctionName="OpenActivityForm" Library="$webresource:new_RibbonActions" />FunctionName must have the name of the function you want to call.Furthermore, if you want to use the form attributes like the Xrm.Page.data.entity.getId() you must add the new_RibbonActions resource as a library to the Case Form.Then, on the OpenActivityForm function just access the required attributes to open the new form.Hope I explained myself correctly.
Regards, João- Edited by J.C. Santos Tuesday, September 6, 2011 3:55 PM
Tuesday, September 6, 2011 3:55 PM -
Thanks for the reply.
Would you like to share the code you put in the JavaScript function? That's my main problem right now.Tuesday, September 6, 2011 11:13 PM -
Hi you are already doing it.
<JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addExistingFromSubGridAssociated" Library="/_static/_common/scripts/RibbonActions.js"> <CrmParameter Value="Incident"/> <CrmParameter Value="FirstPrimaryItemId" /> </JavaScriptFunction>
These lines are passing two parameters to function
Mscrm.GridRibbonActions.addExistingFromSubGridAssociated()There are a lot of things wrong with code you are trying to update the inbuilt function. If you are trying to update the behavior you write your own webresource.
Here is link to create a custom button.
http://www.resultondemand.nl/support/sdk/81b2066f-76c0-4e85-af36-0ef42222a470.htm
when you create a javascript webresource
Use this to pop up window a service activity (window.open("URL")
How to get the addressable forms and passing values to the form have a look at this
http://msdn.microsoft.com/en-us/library/cc150850.aspx
I hope this helps.
Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/- Proposed as answer by Amreek Singh Tuesday, September 6, 2011 11:13 PM
Tuesday, September 6, 2011 11:13 PM -
When I try this code:
<RibbonDiffXml> <CustomActions> <CustomAction Id="Mscrm.SubGrid.activitypointer.NewServiceActivity" Location="Mscrm.SubGrid.activitypointer.MainTab.Management.Controls._children" Sequence="17"> <CommandUIDefinition> <Button Id="Mscrm.Subgrid.activitypointer.NewServiceActivityButton" Command="OpenNewServiceActivityAssociated" LabelText="New Service Activity" ToolTipTitle="New Service Activity" ToolTipDescription="Add new Service Activity to this Case" TemplateAlias="o1" Image16by16="/_imgs/ribbon/CustomEntity_16.png" Image32by32="/_imgs/ribbon/CustomEntity_32.png" /> </CommandUIDefinition> </CustomAction> </CustomActions> <Templates> <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates> </Templates> <CommandDefinitions> <CommandDefinition Id="OpenNewServiceActivityAssociated"> <EnableRules /> <DisplayRules /> <Actions> <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addExistingFromSubGridAssociated" Library="/_static/_common/scripts/RibbonActions.js"> <CrmParameter Value="incident"/> <CrmParameter Value="FirstPrimaryItemId" /> </JavaScriptFunction> </Actions> </CommandDefinition> </CommandDefinitions> <RuleDefinitions> <TabDisplayRules /> <DisplayRules /> <EnableRules /> </RuleDefinitions> <LocLabels /> </RibbonDiffXml>
I get error when I try to import the solution:The 'Value' attribute is invalid - The value 'incident' is invalid according to its datatype 'CrmParameterValue' - The Enumeration constraint failed.
Tuesday, September 6, 2011 11:26 PM -
Because is "incident" is not a valid parameter it should be PrimaryEntityTypeName (it will pass value of the entity you are clicking this button from)
Here is a link to the valid CRMParameteres
http://msdn.microsoft.com/en-us/library/gg309332.aspx
I hope this help.
Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/- Proposed as answer by Amreek Singh Wednesday, September 7, 2011 2:05 AM
Wednesday, September 7, 2011 2:05 AM -
Here is the solution to the problem:
<RibbonDiffXml> <CustomActions> <CustomAction Id="Mscrm.SubGrid.activitypointer.NewServiceActivity" Location="Mscrm.SubGrid.activitypointer.MainTab.Management.Controls._children" Sequence="17"> <CommandUIDefinition> <Button Id="Mscrm.Subgrid.activitypointer.NewServiceActivityButton" Command="OpenNewServiceActivityAssociated" LabelText="New Service Activity" ToolTipTitle="New Service Activity" ToolTipDescription="Add new Service Activity to this Case" TemplateAlias="o1" Image16by16="/_imgs/ribbon/CustomEntity_16.png" Image32by32="/_imgs/ribbon/CustomEntity_32.png" /> </CommandUIDefinition> </CustomAction> </CustomActions> <Templates> <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates> </Templates> <CommandDefinitions> <CommandDefinition Id="OpenNewServiceActivityAssociated"> <EnableRules> <EnableRule Id="Mscrm.Enabled" /> </EnableRules> <DisplayRules /> <Actions> <JavaScriptFunction FunctionName="addNewServiceActivity" Library="$webresource:Incident_main_library.js"> <CrmParameter Value="FirstPrimaryItemId" /> </JavaScriptFunction> </Actions> </CommandDefinition> </CommandDefinitions> <RuleDefinitions> <TabDisplayRules /> <DisplayRules /> <EnableRules /> </RuleDefinitions> <LocLabels /> </RibbonDiffXml>
and in the Incident JS file i have this function:function addNewServiceActivity(incidentid) { Mscrm.AddActivity.addActivityToFormFromsubgrid(4214, incidentid, 112); }
4214 is the typecode for service activity112 for incident.
Mscrm.AddActivity.addActivityToFormFromsubgrid
is a function that comes with CRM 2011.
Wednesday, September 7, 2011 6:09 PM -
The code that i marked as answer works, but when the Account window or Case window load, it shows an error as a pop up box and I have to close it everytime before I want to do something else.
When I try with "Mscrm.AddServiceActivityToPrimaryRecord", it works except when the button is placed on the ribbon in the Related Activities tab on the Case window. In that area the button is disabled. I tried enabling the button with this code but it shows and error.
<CustomActions> <CustomAction Id="Mscrm.SubGrid.activitypointer.NewServiceActivity" Location="Mscrm.SubGrid.activitypointer.MainTab.Management.Controls._children" Sequence="17"> <CommandUIDefinition> <Button Id="Mscrm.Subgrid.activitypointer.NewServiceActivityButton" Command="Mscrm.AddServiceActivityToPrimaryRecord" LabelText="New Service Activity" ToolTipTitle="New Service Activity" ToolTipDescription="Add new Service Activity to this Case" TemplateAlias="o1" Image16by16="/_imgs/ribbon/CustomEntity_16.png" Image32by32="/_imgs/ribbon/CustomEntity_32.png" /> </CommandUIDefinition> </CustomAction> </CustomActions> <Templates> <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates> </Templates> <CommandDefinitions> <CommandDefinition Id="Mscrm.AddServiceActivityToPrimaryRecord"> <EnableRules> <EnableRule Id="Mscrm.Enabled" /> </EnableRules> <DisplayRules /> <Actions> <JavaScriptFunction FunctionName="Mscrm.RibbonActions.addActivityOnForm" Library="/_static/_common/scripts/RibbonActions.js"> <IntParameter Value="4214" /> </JavaScriptFunction> </Actions> </CommandDefinition> </CommandDefinitions>
- Edited by KatRiketa Wednesday, September 14, 2011 4:15 PM
Wednesday, September 14, 2011 4:13 PM