locked
Is it possible to add html web resource dynamically? RRS feed

  • 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:

    Form XML Schema

    <control> (FormXml)

    <webresource> (FormXml)


    Jason Lattimer

    Thursday, October 18, 2012 2:29 AM
    Moderator

All replies

  • Hi,

    I think you already posted this question here.

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.


    Monday, October 15, 2012 9:26 AM
  • Hi,

    Can we attach html webresource to system/Custom entities programmatically in MSCRM 2011

    Thanks,

    Abhishek


    Abhishek

    Monday, October 15, 2012 10:21 AM
  • See this sample in the SDK:

    Sample: Import Files as Web Resources


    Jason Lattimer

    Monday, October 15, 2012 1:23 PM
    Moderator
  • Hi Everyone,

    ms crm 2011 - Has anyone added the html webresource to the section in formxml pragrammatically?

    Thanks


    Rajeev

    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:

    Form XML Schema

    <control> (FormXml)

    <webresource> (FormXml)


    Jason Lattimer

    Thursday, October 18, 2012 2:29 AM
    Moderator
  • 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 AM
    Moderator