Monday, October 24, 2016

Use T-SQL to Parse Dynamics CRM Form XML

It's possible to use SQL Server (including SQL Azure) to parse the XML for CRM forms. With the form's XML, you can run a query to, for example, list all JavaScript libraries applied to a form.

DECLARE @DocHandle int
DECLARE @XmlDocument nvarchar(max)
SET @XmlDocument = N'YOUR CRM FORM XML GOES HERE'
EXEC sp_xml_preparedocument @DocHandle OUTPUT, @XmlDocument
SELECT *
  FROM OPENXML (@DocHandle, '/form/formLibraries/Library',1)
      WITH (name varchar(100),
            libraryUniqueId varchar(50))
EXEC sp_xml_removedocument @DocHandle

Or list all tabs on the form, as in this example.

DECLARE @DocHandle int
DECLARE @XmlDocument nvarchar(max)
SET @XmlDocument = N'YOUR CRM FORM XML GOES HERE'
EXEC sp_xml_preparedocument @DocHandle OUTPUT, @XmlDocument
SELECT *
  FROM OPENXML (@DocHandle, '/form/tabs/tab',1)
      WITH (name varchar(100))
EXEC sp_xml_removedocument @DocHandle

No comments:

Post a Comment