Tag Archives: SQL

CRM : Rescheduling the Update Contract States job

Update Contract States job is CRM 2011 (also for CRM 4.0) system job which runs daily and change the contract status based on contract start date and end date (i.e. change contract from Invoiced to active and from Active to expired).

One of customer’s CRM organization has this job running 10 PM at night and wanted to change this job on particular time (very early in the morning) to make sure contract status are up to date when users starts using CRM system.

There is job editor provided by MS to reschedule CRM system jobs but this does not include this specific job.

so following are steps we undertook with the help of CRM parter/MS support to reschedule this particular job in CRM system.

Step 1: run the following query to find the current Jobs in the relevant CRM organization. (note down the AsyncOperationid returned from this query as we will be using this in next step)

select AsyncOperationid,RecurrenceStartTime,postponeuntil,StatusCode, RecurrencePattern from AsyncOperation WHERE
Name = 'Update Contract States job'
and
StatusCode =10
and RecurrencePattern is not null

following quick details regarding important columns in this table.

RecurrencePattern is used to describe frequency and interval of the system jobs and please refer this article for more information on regarding this.

Postponeuntil is datetime field and indicate when this job will run next time. And it is UTC date meaning if this field contains “2012-10-23 09:08:00.000” and if your time zone is GMT + 1 then this job will run next time on “2012-10-23 10:08:00.000”

RecurrenceStartTime is also UTC datetime field which will be used to set next runtime of job, date part of this field is not important as long as it is set in the past.

Step 2: so using noted down AsyncOperationid in step 1 run following query to update recurrencestarttime, postponeuntil for this Update Contract States job .


update AsyncOperation set
RecurrenceStartTime = '2012-10-22 09:08:00.000',
postponeuntil = '2012-10-23 09:08:00.000'
WHERE AsyncOperationid = '5EB24ECB-60ED-4F59-801D-A6C19465C4D8'

So as per above update, this job will run at 9:08 AM (GMT time) in the morning every day.after job run if you verify the details then it would look as follows. So as you can see system will update postponeuntil (next run time) to next day (24th October) after this job run today (on 23th October).

****Important Notes regarding above change****
above change is unsupported so make sure you apply this change to Dev, Test environment before applying this to Live environment. Also make sure you take back up of database before doing this change.

Hope this helps..

Cheers,
MayankP:)

Advertisements

CRM 4.0 to CRM 2011 Queues Upgrades

There are lots of improvements and enhancement with regards queue in CRM 2011 and they are mentioned in this article

Now if you migrated your organization from CRM 4.0 system the since for each user CRM 4.0 has two queues as mentioned below
1. User’s Private Queue (i.e. Assign Queue)
2. User’s WIP Queue (i.e. In Progress Queue folder)

While upgrading User’s Private Queue is converted as default queue and renamed user’s full name so if user is name mark smith, in CRM 2011 this user will have only one queue named with full user name

All WIP queue is migrated as it is but on them worker Id set to owning user, so since these were the items in user’s In progress queue in CRM 4.0 they are migrated with working user set as owning user.

If you match your queue details with standard CRM 2011 organization (which was not upgrade from CRM 4.0) then you will know that they have got only one named queue and do not have this additional WIP queue.

If users want to match up this queue experience for CRM 2011 environment (migrated from CRM 4.0 system) to new install of CRM 2011 environment then following ate recommended steps for the sae which are mentioned in following article. this article provides the details but does not provide tool or script to do the job, this post will provide tool and script code to achieve this.

http://msdn.microsoft.com/en-us/library/gg327885.aspx

1. Move all items from WIP queue to user’s default queue and set worker id as well
2. Delete or Deactivate the WIP queue

Now each user can manually do above task but if you got large user base then I guess it is better if system admin can do above task for the same.

Following two ways to achieve this,

Option 1: using CRM API to update relevant queue records (Supported)

I have created application which will move all current WIP queue item to user’s named queue and then disables the WIP queue.

This application is shared below.
CRM2011_WIPQueues

Following is few more details regarding this application for the same.

Step 1: after downloading CRM2011_WIPQueues_Upgrades_EXE.zip,extract the zip file.

Step 2: after extracting run the CRM2011_WIPQueues_Upgrades.exe

Step 3: provide CRM server details and then click on “Move Items“ button. Following are example screen print for the same.

One advantage of this application is it is supported but disadvantage is that it could take more then 2-3 hours if your CRM system got really large records in WIP queues but since we have run this only once I prefer this approach.

However there is another faster (but unsupported) method is mentioned below to achieve the same result.

Option 2: using SQL script **UNSUPPORTED**

System administrator can build SQL script to update all relevant queue item records to change queue id from WIP queue to user’s named queue.

Following example screen print for the script for the same for one user, this script can be downloaded from here and change the USER DOMAIN NAME for the relevant user in the following script. Of course this needs to be run for all users in the system.

-- find out all items present in relevant user's WIP queue
-- update user's domain name in query mentioned below
select * from filteredqueueitem
inner join filteredqueue on
filteredqueueitem.queueid = filteredqueue.queueid
inner join filteredsystemuser on
filteredsystemuser.systemuserid = filteredqueue.ownerid
where queuetypecode = 3
and filteredsystemuser.domainname = 'USER DOMAIN NAME'

--Update items in WIP queue to named queue
-- update user's domain name in query mentioned below
Update queueitembase
set queueid = (select filteredqueue.queueid from filteredqueue
inner join filteredsystemuser on
filteredsystemuser.systemuserid = filteredqueue.ownerid
where queuetypecode = 2
and filteredsystemuser.domainname = 'USER DOMAIN NAME')
where queueid = (
select filteredqueue.queueid from filteredqueue
inner join filteredsystemuser on
filteredsystemuser.systemuserid = filteredqueue.ownerid
where queuetypecode = 3
and filteredsystemuser.domainname = 'USER DOMAIN NAME')

One advantage of this approach is that it will complete the moving with few minutes even if million records needs moving but big disadvantage is that we are making change to SQL directly which is considered as *UNSUPPORTED CHANGE * so if you are going for this route make sure you test this script fully on your development/UAT environment thoroughly before running them in to Live environment.

Hope this helps..

Cheers,
MayankP:)

SQL Transaction: Small Tip.

While using CRM 4.0 many times we have to do unsupported changes directly to the database and there is risk involved in running the queries directly to change CRM database record or field.

I have small tip for this using SQL Transaction for this. Before running your Query run begin transaction Command then run your query and check the results.

If results are ok and as expected then run commit transaction Command.

Otherwise if result is not as expected then run rollback transaction Command and that will undo the changes.

see below image for explnation on this..

Hope this helps!!!

Cheers,
MayankP:)

CRM 4.0 Security Privileges

Recently we started getting following error on one of our CRM environment.

Server was unable to process request.
0x80040220
SecLib::CrmCheckPrivilege failed. Returned hr = -2147220960 on UserId: 6e7d3c02-b2c2-df11-a8e6-78e7d1e8d0ae and PrivilegeId: cb4b339f-2b45-447e-bdd3-0bf4bbebc294
Platform

Well this does say it security issue but still does not say which entity it is failing for..Well you can easily track this down using following query. (I.e. replace relevant privilege id as per your requirement)

select name from FilteredPrivilege
where privilegeid = 'cb4b339f-2b45-447e-bdd3-0bf4bbebc294'

As in example it shows user does not have permission to update relevant leads, we given lead update permission to relevant users and that fixed the issue!!

While looking for solution on this problem I also found few CRM Security Reports displaying all role privileges, including hidden privileges.

Cheers,
MayankP:)

Append string value in SQL using XML Path

One of my colleagues has showed me this cool trick…

So many times you need to write code where you needed to append strings values from a field in SQL Table and all the times people uses different approach…cursors, CTE, WHILE loop, doing it from the front end…etc. in SQL

Following is one very cool approach to achieve this in SQL using XML Path.

Hope this helps…