Quantcast
Channel: blog.atwork.at
Viewing all articles
Browse latest Browse all 1118

Project: Benutzerdefinierte Felder in andere Entität kopieren / Copy Custom Fields to Other Entity

0
0
  1. Deutsch
  2. English
  3. Code
  4. Code ECF

Deutsch

Häufig wird in Foren die Frage gestellt, weshalb Werte benutzerdefinierter Felder in einer Ansicht nicht zur Verfügung stehen. Das liegt üblicherweise daran, dass das Feld für eine Entität erstellt wurde, die in der gewünschten Ansicht nicht zur Verfügung steht. So kann es sich um ein Vorgangsfeld handeln, das in der Ansicht Ressource: Einsatz nicht angezeigt werden kann oder um ein Ressourcenfeld, das in der Ansicht Vorgang: Einsatz nicht verfügbar ist. Das ist auch dann der Fall, wenn die Berechnung für Zuordnungszeilen auf Abwärts zuordnen, wenn nicht manuell eingegeben aktiviert ist:

SNAGHTMLb01ce46

Die Feldwerte können jedoch per Makro für jede Zuordnung von einer Entität in die andere übertragen werden. Um die Werte lokaler Felder zu übertragen, können Sie den Code für lokale Felder einsetzen. Wenn Werte für Benutzerdefinierte Enterprise-Felder übertragen werden sollen, verwenden Sie den Code für diese Felder.
Nach Lauf des Makros stellt sich das Ganze dann so dar:

SNAGHTMLb04d481

In Makros implementieren / Implement Macros wird beschrieben, wie ein Makro in Project übernommen werden kann. Mehr Beispielmakros sind unter VBA zu finden.

English

There is often a question in forums why values of custom fields are not available in a specific view. This is usually because the field was created for an entity that is not available in the view you want. It can be an task field that can not be displayed in the Resource Usage view or a resource field that is not available in the Task Usage view. This is also the case if Calculation for assignment rows is set to Rolldown unless manually entered:

image

The field values can be transferred via macro for an assignment from one entity to another. To transfer the values of local fields, you can use the code for local fields. If values for Custom Enterprise fields are to be transmitted, use the code for these fields.

After running the macro, the project looks like this:

SNAGHTMLb1157d0

Implementing Macros / Implement Macros describes how to apply a macro to Project. More sample code is available at VBA.

Code

Sub CopyAssignmentFieldValueTaskToResource()'***********************************************************************************'Code is provided “AS IS” without warranty of any kind, either expressed or implied,'including but not limited to the implied warranties of merchantability and/or'fitness for a particular purpose.'***********************************************************************************'Copy assignment value from Task field "Text1" to Resource field "Text1"'Prerequisite: For both fields, "Roll down unless manually specified" has to be enabled'in Project - Custom FieldsDim P As ProjectDim T As TaskDim R As ResourceDim At As AssignmentDim Ar As Assignment'P is active ProjectSet P = ActiveProject'Loop through all tasksForEach T In P.Tasks'Ignore invalid tasks (empty rows)IfNot T IsNothingThen'Ignore summary tasks - no assignments should be thereIfNot T.Summary Then'Loop through all assignmentsForEach At In T.Assignments'Set R to resource of current assignmentSet R = P.Resources(At.ResourceID)'Set ResourceAssignment to current TaskAssignment'****** INFORMATION ******************'Unfortunatley there is an issue when UniqueIDs for assignments did'not match between TaskAssignment and ResourceAssignment. If there is'a fix in future enable "otion 1" instead of "option 2"'Start option 1 ****************************************************'                Set Ar = R.Assignments.UniqueID(At.UniqueID)'End option 1 ****************************************************'Start option 2 ****************************************************ForEach Ar In R.AssignmentsIf Ar.TaskID = T.ID Then'now we have the correct resource assignmentExitForEndIfNext Ar'End option 2 ****************************************************'Copy value
                Ar.Text1 = At.Text1Next AtEndIfEndIfNext TEndSubSub CopyAssignmentFieldValueResourceToTask()'***********************************************************************************'Code is provided “AS IS” without warranty of any kind, either expressed or implied,'including but not limited to the implied warranties of merchantability and/or'fitness for a particular purpose.'***********************************************************************************'Copy assignment value from Resource field "Text1" to Task field "Text1"'Prerequisite: For both fields, "Roll down unless manually specified" has to be enabled'in Project - Custom FieldsDim T As TaskDim R As ResourceDim At As AssignmentDim Ar As Assignment'P is active ProjectSet P = ActiveProject'Loop through all resourcesForEach R In P.Resources'Ignore invalid resourcesIfNot R IsNothingThen'Loop through all assignmentsForEach Ar In R.Assignments'Consider only assignments for current project (there may by other projects open with the same resources)If Ar.Project = P Then'Set task to current assignment taskSet T = P.Tasks(Ar.TaskID)'Set TaskAssignment to current ResourceAssignment'****** INFORMATION ******************'Unfortunatley there is an issue when UniqueIDs for assignments did'not match between TaskAssignment and ResourceAssignment. If there is'a fix in future enable "otion 1" instead of "option 2"'Start option 1 ****************************************************'                Set At = T.Assignments.UniqueID(Ar.UniqueID)'End option 1 ****************************************************'Start option 2 ****************************************************ForEach At In T.AssignmentsIf At.ResourceID = R.ID Then'now we have the correct task assignmentExitForEndIfNext At'End option 2 ****************************************************'Copy value
                At.Text1 = Ar.Text1EndIfNext ArEndIfNext REndSub

Code ECF

Sub CopyAssignmentFieldValueTaskToResource_ECF()'Copy assignment value from Resource field "MyResourceField" to Task field "MyTaskField" (in this sample)'Prerequisite:'   - For both fields, "Roll down unless manually specified" has to be enabled'   - Resource and Task field names must not contain any spaces (" ")Dim P As ProjectDim T As TaskDim R As ResourceDim At As AssignmentDim Ar As Assignment'P is active ProjectSet P = ActiveProject'Loop through all tasksForEach T In P.Tasks'Ignore invalid tasks (empty rows)IfNot T IsNothingThen'Ignore summary tasks - no assignments should be thereIfNot T.Summary Then'Loop through all assignmentsForEach At In T.Assignments'Set R to resource of current assignmentSet R = P.Resources(At.ResourceID)'Set ResourceAssignment to current TaskAssignment'****** INFORMATION ******************'Unfortunatley there is an issue when UniqueIDs for assignments did'not match between TaskAssignment and ResourceAssignment. If there is'a fix in future enable "otion 1" instead of "option 2"'Start option 1 ****************************************************'                Set Ar = R.Assignments.UniqueID(At.UniqueID)'End option 1 ****************************************************'Start option 2 ****************************************************ForEach Ar In R.AssignmentsIf Ar.TaskID = T.ID Then'now we have the correct resource assignmentExitForEndIfNext Ar'End option 2 ****************************************************'Copy value
                    Ar.MyResourceField = At.MyTaskFieldNext AtEndIfEndIfNext TEndSubSub CopyAssignmentFieldValueResourceToTask_ECF()'Copy assignment value from Task field "MyTaskField" to Resource field "MyResourceField" (in this sample)'Prerequisite:'   - For both fields, "Roll down unless manually specified" has to be enabled'   - Resource and Task field names must not contain any spaces (" ")Dim P As ProjectDim T As TaskDim R As ResourceDim At As AssignmentDim Ar As Assignment'P is active ProjectSet P = ActiveProject'Loop through all resourcesForEach R In P.Resources'Ignore invalid resourcesIfNot R IsNothingThen'Loop through all assignmentsForEach Ar In R.Assignments'Consider only assignments for current project (there may by other projects open with the same resources)If Ar.Project = P Then'Set task to current assignment taskSet T = P.Tasks(Ar.TaskID)'Set TaskAssignment to current ResourceAssignment'****** INFORMATION ******************'Unfortunatley there is an issue when UniqueIDs for assignments did'not match between TaskAssignment and ResourceAssignment. If there is'a fix in future enable "otion 1" instead of "option 2"'Start option 1 ****************************************************'                Set At = T.Assignments.UniqueID(Ar.UniqueID)'End option 1 ****************************************************'Start option 2 ****************************************************ForEach At In T.AssignmentsIf At.ResourceID = R.ID Then'now we have the correct resource assignmentExitForEndIfNext At'End option 2 ****************************************************'Copy value
                    At.MyTaskField = Ar.MyResourceFieldEndIfNext ArEndIfNext REndSub

Viewing all articles
Browse latest Browse all 1118

Latest Images

Trending Articles