Using workflows in Dynamics CRM. Static fields? - dynamics-crm

My first question here. I am relatively new to Dynamics CRM and I am looking to do a customization using workflows and I have run into some issues.
I need to trigger an email to a user if I have 5 records with a specific value chosen in an option set within the last 15 days.I thought I might need a static variable kind of field for the entity. I don't really know how to get that in CRM.
While I have been able to use workflows to get the records within the 2 dates and increment the count for that condition, the count maintained is not static and so it is basically useless for my requirements.
Any suggestions to work around this?

One way of doing it is to have a custom workflow.
Whenever a new record for that entity is created, run this custom workflow and get the count and return it via an Output parameter. Check for the output value and if that is more than the threshold as in the requirement, then consider the step for sending an email to the user, otherwise complete the workflow as succeeded.

Related

Display work items which are waiting until backend service finishes

In my workflow I have iterative loop which check the table value until it matches a workflow value using DB Execute.
This stage arise after completing initial and step After values matches it will proceed to next step.this has created by adding delay function.
However my client required to show the list work items which are pending withing content navigator. Is there a way to achieve this.
Try to add users (who want to track status) in F_Trackers system Workflow Group.

Determine new record in PreWriteRecord event handler and check value of joined field

There is custom field "Lock Flag" in Account BC, namely in S_ORG_EXT_X table. This field is made available in Opportunity BC using join to above table. The join specification is as follows: Opportunity.Account Id = Account.Id. Account Id is always populated when creating new opportunity. The requirement is that for newly created records in Opportunity BC if "Lock Flag" is equal to 'Y', then we should not allow to create the record and we should show custom error message.
My initial proposal was to use a Runtime Event that is calling Data Validation Manager business service where validation rule is evaluated and error message shown. Assuming that we have to decide whether to write record or not, the logic should be placed in PreWriteRecord event handler as long as WriteRecord have row already commited to database.
The main problem was how to determine if it is new record or updated one. We have WriteRecordNew and WriteRecordUpdated runtime events but they are fired after record is actually written so it doesn't prevent user from saving record. My next approach was to use eScript: write custom code in BusComp_PreWriteRecord server script and call BC's method IsNewRecordPending to determine if it is new record, then check the flag and show error message if needed.
But unfortunately I am faced with another problem. That joined field "Lock Flag" is not populated for newly created opportunity records. Remember we are talking about BC Opportunity and field is placed in S_ORG_EXT_X table. When we create new opportunity we pick account that it belongs to. So it reproduceable: OpportunityBC.GetFieldValue("Lock Flag") returns null for newly created record and returns correct value for the records that was saved previously. For newly created opportunities we have to re-query BC to see "Lock Flag" populated. I have found several documents including Oracle's recomendation to use PreDefaultValue property if we want to display joined field value immediately after record creation. The most suitable expression that I've found was Parent: BCName.FieldName but it is not the case, because active BO is Opportunity and Opportunity BC is the primary one.
Thanks for your patience if you read up to here and finally come my questions:
Is there any way to handle PreWrite event and determine if it is new record or not, without using eScript and BC.IsNewRecordPending method?
How to get value of joined field for newly created record especially in PreWriteRecord event handler?
It is Siebel 8.1
UPDATE: I have found an answer for the first part of my question. Now it seems so simple to me that I am wondering how I haven't done it initially. Here is the solution.
Create Runtime Event triggered on PreWriteRecord. Specify call to Data Validation Manager business service.
In DVM create a ruleset and a rule where condition is
NOT(BCHasRows("Opportunity", "Opportunity", "[Id]='"+[Id]+"'", "AllView"))
That's it. We are searching for record wth the same Row Id. If it is new record there should't be anything in database yet (remember that we are in PreWriteRecord handler) and function returns FALSE. If we are updating some row then we get TRUE. Reversing result with NOT we make DVM raise an error for new records.
As for second part of my question credits goes to #RanjithR who proposed to use PickMap to populate joined field (see below). I have checked that method and it works fine at least when you have appropriate PickMap.
We Siebel developers have used scripting to correctly determine if record is new. One non scripting way you could try is to use RuntimeEvents to set a profileattribute during the BusComp NewRecord event, then check that in the PreWrite event to see if the record is new. However, there is always a chance that user might undo a record, those scenarios are tricky.
Another option, try invokine the BC Method:IsNewRecordPending from RunTime event. I havent tried this.
For the second part of the query, I think you could easily solve your problem using a PickMap.
On Opportunity BC, when your pick Account, just add one more pickmap to pick the Locked flag from Account and set it to the corresponding field on Opportunity BC. When the user picks the Account, he will also pick the lock flag, and your script will work in PreWriteRecord.
May I suggest another solution, again, I haven't tried it.
When new records are created, the field ModificationNumber will be set to 0. Every time you modify it, the ModificationNumber will increment by 1.
Set a DataValidationManager ruleset, trigger it from PreSetFieldValue event of Account field on Opportunity BC. Check for the LockFlag = Y AND (ModificationNumber IS NULL OR ModificationNumber = 0)) and throw error. DVM should throw error when new records are created.
Again, best practices say don't use the ModNumbers. You could set a ProfileAttribute to signal NewRecord, then use that attribute in the DVM. But please remember to clear the value of ProfileAttribute in WriteRecord and UndoRecord.
Let us know how it went !

advanced duplication detection & actions in dynamics CRM

I'm new to dynamics CRM, and I'm wondering if, and how, the following scenario can be supported:
When a record is created / updated, I want to be able to define how to find duplicate records.
If a duplicate is found, I want to be able to define automatic actions based on the new record's properties.
(for example- when a case is created, check for duplicate cases based on 'customer' and 'owner' fields. If a duplicate is found, then: if the duplicate case's status is not 'active' then go ahead and create a new record. otherwise- update some of the existing record's fields based on the new record).
The first part can easily be accomplished using duplication detection settings, but I don't think they allow for any complex logic when a duplicate is discovered.
The second part can easily be accomplished using workflows. however, I don't think that they offer conditions that check other records. I've looked into customizing workflows, but all I could find was how to customize actions, and not conditions.
Does dynamics CRM offer any solution to this type of scenario?
Yes, it does. You can accomplish this using CRM plugin. It should be Pre execution plug ins registered on Create and on Update events.

Sharepoint Designer 2007 Workflows

In Sharepoint designer 2007, I am creating a workflow where I am trying to use 'collect data from a user' for multiple users. In my document library, I have a list name field. That list name field ties to a list which has between 1-15 users in the associated list. I only need to collect data from user for those users in the list that are not null/empty. I would also like to collect data from the users at the same time (parallel).
It appears you can only use parallel within one workflow step. Within one workflow step, it doesn't appear that you can set multiple conditions/actions.
What I need to do is this:
Condition 1: If variable:reviewer1 is not empty
Action 1: Collect Document Review from variable:reviewer1 (output to ...)
Condition 2: If variable:reviewer2 is not empty
Action 2: Collect Document Review from variable:reviewer2 (output to...)
Is there a way to do this that I'm missing?
Thanks!
It'll be tedious, but I'd suggest creating N steps (where N = the number of parallel tasks you want)
Each step will generally do the following:
Check if the current reviewer field is empty (if so, skip to the next step)
Create a new "Task" item in a (task) List
Send an email to the person you assigned the task to
Then you'll need to somehow stop your workflow until all of the tasks have been completed. This part gets a bit trickier, but do some searches on creating a State Machine workflow in SharePoint Designer and you'll be on the right track.
Really though, this sounds like a workflow that's too complex for SPD. Use Visual Studio or some 3rd-party workflow solution if at all possible.

Autonumbering in new entity

I have an custom entity which needs to have a case number for an XRM Application, can I generate a case number from the Service -> Case.
If this is not possible, how can I do this with a plugin, I've looked at the crmnumbering.codeplex.com but this doesn't support 2011, anybody outthere have a solution or should I rewrite it myself?
thanks
I've ran into this same type of issue (I need a custom # for an entity). Here's how you can do it:
Create an Entity called "Counter"
Add a field called "new_customnumber", make it a string or a number depending on what you want
Create a new record for that entity with whatever you want in the new_customnumber field (let's say "10000")
Create a plugin (EntityNumberGenerator) that goes out and grabs that record (you'll probably want to set the security on this record/entity really tight so no one can mess with the numbers)
On Create of the "custom entity" fire the plugin. Grab the value in new_customnumber save it to the "custom entity" (let's say in a "case" field) increment the new_customnumber and save it to the Counter entity.
Warning, I'm not sure how this is with concurrency. Meaning I'm not sure if 2 custom entities being created at the same time can grab the same number (I haven't ran into an issue yet). I haven't figured out a way to "lock" a field I've retrieved in a plugin (I'm not sure it's possible).
You will be unable to create a custom number for custom entities from the normal area you set a case number.
Look at the CRM2011sdk\sdk\samplecode\cs\plug-ins\accountnumberplugin.cs plugin. It's really similar to what you want.
Ry
I haven't seen one for 2011 yet. Probably easiest to write it yourself.
I've always created a database with a table with a single column which is an IDENTITY column. Write an SP to insert, save the IDENTITY value to a variable, and DELETE the row all within a transaction. Return the variable. Makes for a quick and easy plug-in and this takes care of any concurrency issues.
The performance is fast and the impact to your SQL server is minimal.

Resources