Using FOR XML to build bulkreg XML for DNN
January 28th, 2009DotNetNuke is a great portal and there are many modules out there to make working with it easier. One such module is BulkReg. It allows you to throw data into it in a csv or xml file and it adds, deletes, or updates those users in DNN.
I ask my clients for their member list in a xls file and then I import that information into a table in a SQL Server database. Now with it in a table I can use the FOR XML statement to build my xml for the module. I built a Stored Procedure with paging functionality because I have found that i'll run into time-out issues if I try to load all the members at the same time. The SP asks for the PageIndex and then the Size of each page.
CREATE PROCEDURE [dbo].[GetDNNMemberXML]
-- Add the parameters for the stored procedure here
@PageIndex int = 1,
@PageSize int = 500
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
WITH TransformedMembers AS (
SELECT ROW_NUMBER() OVER (ORDER BY UserName ASC)
AS Row,
USERNAME,
FIRSTNAME,
LASTNAME,
UNIT,
STREET,
CITY,
REGION,
POSTALCODE,
TELEPHONE,
EMAIL,
FROM dbo.DNNMembers)
SELECT
'R' AS [KEY],
USERNAME,
USERNAME AS DISPLAYNAME,
FIRSTNAME,
LASTNAME,
UNIT,
STREET,
CITY,
REGION,
'US' AS COUNTRY,
POSTALCODE,
TELEPHONE,
EMAIL,
'UserRole' AS "ROLES/ROLE/ROLENAME"
FROM TransformedMembers WHERE Row BETWEEN (@PageIndex - 1) * @PageSize + 1 AND @PageIndex*@PageSize
FOR XML PATH('USER'), ROOT('ROOT')
END
GO
I used this MSDN article and this other article to figure out what statements to use for the FOR XML and this one for Paging. The functions used for paging in this SP are only available in SQL Server 2005. Hope somebody finds this useful.
Absolute Positioning Inside Relative Positioning
January 28th, 2009I like programming but it's really hard to get good at a language when you don't use it very often. I was having some issues with positioning items using css and div tags. I found this article and made my world a better place.
Making a global variable in a form
January 15th, 2009CRM has the OnLoad, OnSave, and OnChange events to add JScript to you so can customize functionality in your forms. I wanted to set a value in the OnLoad event and then access it in the OnSave.
One way to do this would to create an attribute for the entity add it to the form and hide it in some way. The problem I have with this method is when you set that attribute the form is flagged as dirty because a value was changed, and depending on other logic you have in the form this could cause issues.
I looking around the web and then finally made a post on the CRM Newsgroups and got a reply. I found that you can add you own properties to the window property. So in your OnLoad event you could do do this..
window.specialVar = true
and then this in the OnSave event
if(window.specialVar == true){
//run code
}
Hopefully you find this as helpful as I did.
Companion.JS is Firebug for IE
January 13th, 2009I love Firebug but it only works for IE. They do have Firebug Lite for other browsers but it doesn't always work with all applications. In my searching I found a tool called Companion.JS. I use it sometimes when debugging issues with my CRM JS (You have to access CRM using the http://[server]/loader.aspx page to do this). For the most part it helps me get the job done. I find that depending on the situation it's quicker then using the debugger statement in my code.
Keep in mind that this doesn't handle debugging JS that has been loaded into the document dynamically so if you're including external JS in your onload event then you need to place it directly in the onload event while debugging. Hopefully they add more features in the feature.
Ascentium made a CrmService Library
January 13th, 2009I have been looking around forever for some sort of CrmService library and Ascentium has made one. They also made it a while back so that would mean I'm not very good at searching. Well check it out. If you do working with CRM and JS then it will save you a load of time.