Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Best practice when using C# with Custom Activity Forms

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I created a Custom Activity that includes 3 Forms. When I create a new Activity, it displays a Form that is not ideal to say the least. I can add a new Tab to the Form, but I can't get rid of Controls or edit the General tab using C# code. I did figure out how to Disable a Control using C#, but the Control is still visible.

Form created by new Custom Activity.

aaa25a.PNG

XML of Form above.

<form>
  <tabs>
    <tab verticallayout="true" id="{4bb16a6a-31ad-4cc3-89d9-0f5c0ce1513b}" IsUserDefined="1">
      <labels>
        <label description="General" languagecode="1033" />
      </labels>
      <columns>
        <column width="33%">
          <sections>
            <section showlabel="false" showbar="false" IsUserDefined="0" id="{c8ae51d8-372a-400c-b84e-f902a2556435}">
              <labels>
                <label description="General" languagecode="1033" />
              </labels>
              <rows>
                <row>
                  <cell id="{12bb5f80-fe02-4c94-bdb6-d1f2698a2a71}">
                    <labels>
                      <label description="Subject" languagecode="1033" />
                    </labels>
                    <control id="subject" classid="{4273EDBD-AC1D-40d3-9FB2-095C621B552D}" datafieldname="subject" />
                  </cell>
                </row>
                <row>
                  <cell id="{2a9fcaf8-9dfc-4be7-8796-41eb5ed21680}">
                    <labels>
                      <label description="Owner" languagecode="1033" />
                    </labels>
                    <control id="ownerid" classid="{270BD3DB-D9AF-4782-9025-509E298DEC0A}" datafieldname="ownerid" />
                  </cell>
                </row>
                <row>
                  <cell id="{db978cab-ae1b-4b10-a7dd-4d51c2bf90f1}">
                    <labels>
                      <label description="Regarding" languagecode="1033" />
                    </labels>
                    <control id="regardingobjectid" classid="{F3015350-44A2-4aa0-97B5-00166532B5E9}" datafieldname="regardingobjectid" />
                  </cell>
                </row>
              </rows>
            </section>
          </sections>
        </column>
        <column width="66%">
          <sections>
            <section showlabel="false" showbar="false" id="{bef99b59-4504-49ab-ada6-d1a3d486dafb}" IsUserDefined="0" height="auto">
              <labels>
                <label description="Notes" languagecode="1033" />
              </labels>
              <rows>
                <row>
                  <cell showlabel="false" rowspan="15" auto="false" id="{ec6122ad-cbe9-4a39-8206-8abe1fd7d4f1}">
                    <labels>
                      <label description="Note Text" languagecode="1033" />
                    </labels>
                    <control id="notescontrol" classid="{06375649-c143-495e-a496-c962e5b4488e}">
                      <parameters>
                        <DefaultTabId>NotesTab</DefaultTabId>
                      </parameters>
                    </control>
                  </cell>
                </row>
                <row />
                <row />
                <row />
                <row />
                <row />
                <row />
                <row />
                <row />
                <row />
                <row />
                <row />
                <row />
                <row />
                <row height="auto" />
              </rows>
            </section>
          </sections>
        </column>
      </columns>
    </tab>
  </tabs>
  <header id="{e4f23238-c7f0-48e0-a05b-5d45cbf8019e}" celllabelposition="Top" columns="1111" labelwidth="115">
    <rows>
      <row>
        <cell id="{4af19ef2-9557-4baa-8603-4d3d3411b6a8}">
          <labels>
            <label description="Priority" languagecode="1033" />
          </labels>
          <control id="header_prioritycode" classid="{3EF39988-22BB-4f0b-BBBE-64B5A3748AEE}" datafieldname="prioritycode" disabled="false" />
        </cell>
        <cell id="{c576970e-fdf3-4580-9741-359efb7c800a}">
          <labels>
            <label description="Due Date" languagecode="1033" />
          </labels>
          <control id="header_scheduledend" classid="{5B773807-9FB2-42db-97C3-7A91EFF8ADFF}" datafieldname="scheduledend" disabled="false" />
        </cell>
        <cell id="{a28f5773-dc63-4086-8897-024285249534}">
          <labels>
            <label description="Activity Status" languagecode="1033" />
          </labels>
          <control id="header_statecode" classid="{3EF39988-22BB-4f0b-BBBE-64B5A3748AEE}" datafieldname="statecode" disabled="false" />
        </cell>
        <cell id="{e84997f0-6c1d-449a-9ef1-c95262fa7621}">
          <labels>
            <label description="Owner" languagecode="1033" />
          </labels>
          <control id="header_ownerid" classid="{270BD3DB-D9AF-4782-9025-509E298DEC0A}" datafieldname="ownerid" disabled="false" />
        </cell>
      </row>
    </rows>
  </header>
</form>

Note: If using this Form, I would like to remove the Notes Control, add more Controls to the General Tab
and move the Priority, Due Date, Activity Status etc... to the first column.

I've can also create a new Form the way I want it using C#, but I can't figure out how to make the Activity use the new Form using C#. I've tried deleting the existing Form and setting IsDefault to true on the new Form, but that doesn't work. I get an error when I try to create a new Activity.

I've also tried updating the existing Form with new FormXml, but when I try to create a new Activity, I get an error.

What is the best method or approach to this problem. 

1) Create a new Form that loads when a new Activity is created. Delete the old Form.

2) Edit the existing form

I've used plugins that seem to be able to create and use custom Forms, so I know it's possible.

If possible, please provide code snippets with your response. Any help is much appreciated. Thanks!

*This post is locked for comments

  • Suggested answer
    Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: Best practice when using C# with Custom Activity Forms

    Not sure why you are editing form layout xml directly. You can edit the form using WYSIWYG editor (drag & drop) by clicking the "Form Editor" button in your screenshot. You can remove the section/tab, hide them, add new section/tab, fields, etc. Then just save & publish. Even you can preview the form before publishing.

    About using brand new forms - you can create new or clone the existing form by doing "save as", this will backup the existing form & you can play around the new form. Also you can deactivate the existing forms or remove the visibility by removing security roles from "Form editor".

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans