Calculate duration of project in Dynamics CRM 365 -


in our dynamics 365, each project - we're showing created on date field. field represents date on project created.

created on

however, we're supposed show duration of project.

like @ many places, have these on stackoverflow:

  • asked n minute ago
  • asked n day ago
  • asked n week ago
  • asked n month ago
  • and on...

we wanted show:

  • created n minute ago
  • created n day ago
  • created n week ago
  • created n month ago
  • and on...

how calculate duration of project in dynamics crm 365?

running jobs not option us

if need fields calculated display purposes this

  1. create new fields
  2. register new plugin on post retrieve , retrievemultiple of project entity
  3. copy logic code below, swapping entity/field names needed.

what code doing intercepting contact records whenever they're displayed in crm. means in grids, forms, dashboards etc. it'll calculate time difference on spot , populate fields result. populating entity object in outputparameters, front end receives values , can display them appropriate.

the downside here because fields calculated directly in crm won't able write ssrs reports data isn't persisted database. if implement , go sql query against fields you'll find them null. fields merely act placeholders. (see screenshots)

protected void executeprevalidatecontactretrieve(localplugincontext localcontext)     {         if (localcontext == null)         {             throw new argumentnullexception("localcontext");         }          ipluginexecutioncontext plugincontext = localcontext.pluginexecutioncontext;          if (plugincontext.outputparameters.contains("businessentity"))         {             entity target = (entity)plugincontext.outputparameters["businessentity"];             populatekpis(localcontext.organizationservice, target);         }         else if (plugincontext.outputparameters.contains("businessentitycollection"))         {             entitycollection contacts = (entitycollection)localcontext.pluginexecutioncontext.outputparameters["businessentitycollection"];              foreach (entity c in contacts.entities)                 populatekpis(localcontext.organizationservice, c);         }     }      public void populatekpis(iorganizationservice orgservice, entity contact)     {         datetime createdon;          if (!contact.contains("createdon"))             createdon = orgservice.retrieve(contact.logicalname, contact.id, new columnset("createdon")).getattributevalue<datetime>("createdon");         else             createdon = contact.getattributevalue<datetime>("createdon");          timespan diff = datetime.now - createdon;          contact["mst_secondssincecreation"] = math.floor(diff.totalseconds).tostring();         contact["mst_minutessincecreation"] = math.floor(diff.totalminutes).tostring();         contact["mst_hourssincecreation"] = math.floor(diff.totalhours).tostring();     } 

evidence:

enter image description here enter image description here


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -