Answered by:
Auto Fill 'Primary Owner' field with user who is creating the incident

Question
-
Hello -
is there any way to auto populate the 'Primary Owner' field when creating an incident request with the user who is creating the incident?
This would save our helpdesk a lot of time by not having to fill in the primary owner - as they are always going to be the primary owner.
regards,
Thursday, July 21, 2011 6:35 PM
Answers
-
You would need to create a custom workflow that triggers on incident creation that checks the CreatedByUser relationship and copies this to the PrimaryOwner relationship.
For example:
//emoIR contains your incident already
//Created by user relationshhip Guid
Guid relCreated = new Guid("df738111-c7a2-b450-5872-c5f3b927481a");//Firstly, get the CreatedBy User of emoIR
EnterpriseManagementObject emoCreatedByUser = null;foreach (EnterpriseManagementRelationshipObject<EnterpriseManagementObject> obj in
emg.EntityObjects.GetRelationshipObjectsWhereSource<EnterpriseManagementObject>(emoIR.Id, TraversalDepth.OneLevel, ObjectQueryOptions.Default))
{
if (obj.RelationshipId == relCreated)
{
//Set created by user
emoCreatedByUser = obj.TargetObject;
break;
}
}if (emoCreatedByUser != null)
{//Create new primary owner relationship
ManagementPackRelationship relPrimaryOwner =
emg.EntityTypes.GetRelationshipClass(new Guid("42179172-3d24-cfc8-3944-b0a18f550214"));
CreatableEnterpriseManagementRelationshipObject cemroPrimaryOwner =
new CreatableEnterpriseManagementRelationshipObject(emg, relPrimaryOwner);//Set the source and target...
cemroPrimaryOwner.SetSource(emoIR);
cemroPrimaryOwner.SetTarget(emoCreatedByUser);
cemroPrimaryOwner.Commit();
}Check here under "how we built the solution" for instructions on creating a worfklow activity library:
- Proposed as answer by Rob.Ford Sunday, July 24, 2011 9:15 PM
- Marked as answer by Andreas BaumgartenMVP Friday, October 5, 2012 6:56 PM
Thursday, July 21, 2011 7:17 PM
All replies
-
You would need to create a custom workflow that triggers on incident creation that checks the CreatedByUser relationship and copies this to the PrimaryOwner relationship.
For example:
//emoIR contains your incident already
//Created by user relationshhip Guid
Guid relCreated = new Guid("df738111-c7a2-b450-5872-c5f3b927481a");//Firstly, get the CreatedBy User of emoIR
EnterpriseManagementObject emoCreatedByUser = null;foreach (EnterpriseManagementRelationshipObject<EnterpriseManagementObject> obj in
emg.EntityObjects.GetRelationshipObjectsWhereSource<EnterpriseManagementObject>(emoIR.Id, TraversalDepth.OneLevel, ObjectQueryOptions.Default))
{
if (obj.RelationshipId == relCreated)
{
//Set created by user
emoCreatedByUser = obj.TargetObject;
break;
}
}if (emoCreatedByUser != null)
{//Create new primary owner relationship
ManagementPackRelationship relPrimaryOwner =
emg.EntityTypes.GetRelationshipClass(new Guid("42179172-3d24-cfc8-3944-b0a18f550214"));
CreatableEnterpriseManagementRelationshipObject cemroPrimaryOwner =
new CreatableEnterpriseManagementRelationshipObject(emg, relPrimaryOwner);//Set the source and target...
cemroPrimaryOwner.SetSource(emoIR);
cemroPrimaryOwner.SetTarget(emoCreatedByUser);
cemroPrimaryOwner.Commit();
}Check here under "how we built the solution" for instructions on creating a worfklow activity library:
- Proposed as answer by Rob.Ford Sunday, July 24, 2011 9:15 PM
- Marked as answer by Andreas BaumgartenMVP Friday, October 5, 2012 6:56 PM
Thursday, July 21, 2011 7:17 PM -
I copied the script to a custom workflow in a 2016 environment but it isn't working. Anyone who could tell me how to get this working? Scripting is not really my kind of thing...Tuesday, June 20, 2017 12:50 PM