cancel
Showing results for 
Search instead for 
Did you mean: 

Get Date Stored using Workflow Unity API in a Workflow Process

GILBERTO_CORUJO
Champ on-the-rise
Champ on-the-rise

Hi


How can I get the Date Stored of the current document using Workflow Unity API?

I appreciate your help!


Gilbert

--------------------------------------------

// Skeleton generated by Hyland Unity Editor on 3/18/2016 12:12:28 PM
namespace RealNameDataTimeScriptNote2
{
using System;
using System.Text;
using Hyland.Unity;


/// <summary>
/// RealName - DataTime Script Note(2)
/// </summary>
public class RealNameDataTimeScriptNote2 : Hyland.Unity.IClientWorkflowScript
{

#region IClientWorkflowScript
/// <summary>
/// Implementation of <see cref="IClientWorkflowScript.OnClientWorkflowScriptExecute" />.
/// <seealso cref="IClientWorkflowScript" />
/// </summary>
/// <param name="app"></param>
/// <param name="args"></param>
public void OnClientWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.ClientWorkflowEventArgs args)
{
// Add Code Here
Document currentDocument = args.Document;
DocumentLock lockInfo = null;

try
{
User user = currentDocument.CreatedBy;
string name = user.RealName;
//string name = app.CurrentUser.RealName;
//string email = app.CurrentUser.EmailAddress;
DateTime DateandTime = currentDocument.DateStored;
//string displayName = user.DisplayName;
string keyword = "STU-NCFE Realname";
string keyworddatetime = "STU-NCFE Date and Time";

//app.Diagnostics.Write("Name: " + name);
//app.Diagnostics.Write("Real Name: " + realName);
//app.Diagnostics.Write("Display Name: " + displayName);

//string name = app.CurrentUser.RealName;
//string email = app.CurrentUser.EmailAddress;

lockInfo = currentDocument.LockDocument();

if (lockInfo.Status == DocumentLockStatus.LockObtained)
{
KeywordModifier keywordMod = currentDocument.CreateKeywordModifier();
keywordMod.AddKeyword(keyword, name);
keywordMod.AddKeyword(keyworddatetime, DateandTime);
app.Diagnostics.Write(keyword + ": " + name);
keywordMod.ApplyChanges();
}
else
{
app.Diagnostics.Write("Document already locked by: " + lockInfo.UserHoldingLock.DisplayName);
}
}
catch (UnityAPIException e)
{
app.Diagnostics.Write(e);
}
catch (Exception ex)
{
app.Diagnostics.Write(ex);
}
finally
{
if (lockInfo != null)
{
lockInfo.Release();
}
}
}
#endregion
}
}

1 ACCEPTED ANSWER

Zhengxin_Guo
Confirmed Champ
Confirmed Champ

Hi! Gilberto,

The property Hyland.Unity.Document.DateStored should give you the date time of the document was stored.

Hope this answers your question. Please let me know if you have any questions. Thanks!

 

View answer in original post

5 REPLIES 5

Hi! Gilberto,
Your script looks good! Could you please try to add the code "app.Diagnostics.Write(keyworddatetime + ": " + DateandTime);" before the keyword modification gets applied? In that way, we can check the “Unity API” tab in diagnostic console to know if we actually receive the keyword DateStored correctly.
If we do receive a correct date time, there must be a failure of applying the keyword, or maybe the keyword was applied successfully but get cleared out afterwards by other actions(workflow). If that is the case, it would be better to ask for help from technical support to figure out what we missed.