Answered by:
Is it possible to add html web resource dynamically?

Question
-
Hi everyone,
Is it possible to add "html web resource" dynamically through plugin code when a record is created?
Scenario is as follows:
I have created one custom entity. This entity has one field named "new_entityname".
So, when record is created in this custom entity and in that when we are adding the entity name say "xyz"(in new_entityname field), then plugin should fire.
This plugin should add existing "html web resource", to the "xyz" entity form.
Thanks,
Rajeev
Monday, October 15, 2012 9:21 AM
Answers
-
Definitely possible. Once you get the formXML it is just a matter of creating the proper XML elements. It would be a good idea to manually add what you want to a form and see what the resulting XML looks like and then mimic that.
Once you get to your "rows" element, you can use code similar to this to add the web resource.
XElement row = new XElement("row"); XElement cell = new XElement("cell"); cell.Add(new XAttribute("id", "{" + Guid.NewGuid().ToString() + "}")); //Any guid XElement control = new XElement("control"); control.Add(new XAttribute("id", "Webresource_234")); //Choose the name control.Add(new XAttribute("classid", "{9FDF5F91-88B1-47f4-AD53-C11EFC01A01D}")); //Defined by SDK XElement parameter = new XElement("parameters"); control.Add(parameter); XElement url = new XElement("Url", "new_yourwebresource");//Web Resource name parameter.Add(url); cell.Add(control); row.Add(cell); rows.FirstOrDefault().Add(row);
Reference Links:
Jason Lattimer
- Proposed as answer by JLattimerMVP, Moderator Thursday, October 18, 2012 2:29 AM
- Marked as answer by CRM Rajeev Saturday, October 20, 2012 2:53 AM
Thursday, October 18, 2012 2:29 AMModerator
All replies
-
-
Hi,
Can we attach html webresource to system/Custom entities programmatically in MSCRM 2011
Thanks,
Abhishek
Abhishek
- Merged by Andrii ButenkoMVP, Moderator Monday, October 15, 2012 10:33 AM
Monday, October 15, 2012 10:21 AM -
Monday, October 15, 2012 1:23 PMModerator
-
Hi Everyone,
ms crm 2011 - Has anyone added the html webresource to the section in formxml pragrammatically?
Thanks
Rajeev
- Merged by Andrii ButenkoMVP, Moderator Monday, October 15, 2012 2:44 PM
Monday, October 15, 2012 2:23 PM -
Definitely possible. Once you get the formXML it is just a matter of creating the proper XML elements. It would be a good idea to manually add what you want to a form and see what the resulting XML looks like and then mimic that.
Once you get to your "rows" element, you can use code similar to this to add the web resource.
XElement row = new XElement("row"); XElement cell = new XElement("cell"); cell.Add(new XAttribute("id", "{" + Guid.NewGuid().ToString() + "}")); //Any guid XElement control = new XElement("control"); control.Add(new XAttribute("id", "Webresource_234")); //Choose the name control.Add(new XAttribute("classid", "{9FDF5F91-88B1-47f4-AD53-C11EFC01A01D}")); //Defined by SDK XElement parameter = new XElement("parameters"); control.Add(parameter); XElement url = new XElement("Url", "new_yourwebresource");//Web Resource name parameter.Add(url); cell.Add(control); row.Add(cell); rows.FirstOrDefault().Add(row);
Reference Links:
Jason Lattimer
- Proposed as answer by JLattimerMVP, Moderator Thursday, October 18, 2012 2:29 AM
- Marked as answer by CRM Rajeev Saturday, October 20, 2012 2:53 AM
Thursday, October 18, 2012 2:29 AMModerator -
One extra point to add is that the data changes you make will be to metadata. Internally, CRM uses different transaction isolation levels for metadata changes, compared to that used for data changes. A consequence of this is that your code may fail if you run the plugin synchronously. However, you can get around this by running it asynchronously
Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
Thursday, October 18, 2012 4:12 AMModerator