Get Approver/Editor in Custom Workflow

Posted by Community Admin on 04-Aug-2018 15:39

Get Approver/Editor in Custom Workflow

All Replies

Posted by Community Admin on 25-Mar-2014 00:00

I have a custom workflow that generates custom emails to Approvers, Editors, Publishers.  I am looking for a way to get the user who Edited or Approved the current item within the workflow.  My initial thought would be to get Last Modified User.  Does something else exist where I could get this information or would I need to get Last Modified User?  We are running Sitefinity 5.4 4040.

Posted by Community Admin on 14-Apr-2014 00:00

Hi,

For this purpose you can use the ApprovalRecords. These records track the state of the item during it's whole workflow . E.g I create a page, send it for approval, send it for publishing, reject it., send it for publishing again and finally publish it. Here is the outcome in the database ( see approval-records.png).

I've prepared an example using Pages how to work with the API for approval records.
Each status represents a different state of the item. The example is for pages but should work for content items.

var pageManager = PageManager.GetManager();
var userManager = UserManager.GetManager();
 
var recordMap = pageManager.GetPageNode(Guid.NewGuid()).ApprovalTrackingRecordMap;
var records = recordMap.ApprovalRecords.OrderBy(x => x.LastModified);
    //add multilingual filter if nessesery
    //.Where(x => x.Culture == CultureInfo.GetCultureInfo("en"));
foreach (var record in records)
    //This shows the state of the item during the state operation
    //E.g User A send the item for publishing.
    //The bellow two variables will hold User A & stateOnOperation will show AwaitingPublishing.
    var stateOnOperation = record.Status;
    var userId = record.UserId;
    var user = userManager.GetUser(userId);   

Important Note
As of 7.0 approval records have been refactored and this API is no longer usable. I'm giving you an example with the 7.0 API.
You need to include the namespace "Telerik.Sitefinity"

var pageManager = PageManager.GetManager();
var userManager = UserManager.GetManager();
 
var page = pageManager.GetPageNode(Guid.NewGuid());
var records = page.GetApprovalRecords();
//add multilingual filter if nessesery
//.Where(x => x.Culture == CultureInfo.GetCultureInfo("en"));
foreach (var record in records)
     
    //This shows the state of the item during the state operation
    //E.g User A send the item for publishing.
    //The bellow two variables will hold User A & stateOnOperation will show AwaitingPublishing.
    var stateOnOperation = record.Status;
    var userId = record.UserId;
    var user = userManager.GetUser(userId);


Regards,
Martin Gebov
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 04-Sep-2015 00:00

Hi Martin, stealing this thread.

I have a problem with the approvalrecords. I have a product importer that imports new products and updates products on daily basis. The problem is that my approvalrecords now is over 8 GB (!!!). Many of the post have been created when we had bugs and issues, but since there is much changes to the products it will generate many approval posts.

 

Maybe there is something wrong with the import function, but the main issue now is to clear out the old ones. I've noticesed that I can get all from product.ApprovalTrackingRecordMap.ApprovalRecords and also product.GetCurrentApprovalTrackingRecord(cultureInfo)

 

Is it safe to delete all the other records for that culture, except the current? If so, how do I map the culture of the ApprovalRecords? You write that you shoud be able to do .Where (a => a.Culture == CultureInfo.GetCultureInfo("en")) but Culture is an int, and cultureInfo is surly not an int ;)

 

Sitefinity version 6.3 and over 40k of products. If possible, I would like to disable approval posts for Products all together, but I don't know if it is possible

 

This thread is closed