mercoledì 9 maggio 2012 12:45
We have a Project With a custom field cf1. We have another project level custom field cf2. cf1 is tied to a lookup table. When we create a project in pwa then cf1 field needs to be set. After the project is created i need to set the cf2 field programatically depending on the cf1 value set at creation. I tried to ovverride the Created event in the Project (or OnCreated in the C# code) but unfortunately while the project was created, the custom field value was not, so i couldn't do it here.
Do you have any advice where I should do this? In what event should this be done?
Tutte le risposte
mercoledì 9 maggio 2012 12:59In OnCreated you do not have access to the dataset, only to a couple of properties such as the PROJ_UID. To get hold of the dataset you need to trap teh OnCreating event, in which the dataset is passed. Within that dataset I would expect that you also see the custom fields that are already assigned. It may be possible though, that custom fields are part of a subsequent save, which would require to trap the OnUpdating/OnUpdated event. This event though is invoked with every change, so you must define a strategy to detect your initial scenario. One route to go could be in the OnUpdating event to retrieve the project dataset (from the working store) and compare it against the dataset passed with the event. A change from nothing to something comes probably close to the iniitial sequence during creation. Hope this helps...
mercoledì 9 maggio 2012 13:17
Tahnk you for the quick answer, unfortunately this does not seem to wrok. I ovverrode the OnUpdated event, and placed a breakpoint in it, but the Project creation process did not fire this event.
Also, in the OnCreated event I cheked the custom field value directly in the database but it was not in it yet, so probably it is done after the project creation as u suggested.
So I still have a problem to catch this somewhere, the dataset is not a problem since i can get the data from the db directly if i need to. The problem is i need an event where the project and the custom field is created or updated already.
Now I will try every event I can think of, maybe i can catch the right one :)
mercoledì 9 maggio 2012 15:25
Check OnCreating and its eventargs. The dataset therein should contain than your custom field. Be aware though that you cannot update the dataset - you need to submit a seperate update request to set your additional field values. I'm not sure if you can piggyback on the already established session - if not you have some transactional challenges, as your update request than needs to be queued seperately.
lunedì 14 maggio 2012 19:06
Why don't you try the CF2's formula field? Manipulate value of CF1 the way you wanted and use that in your CF2's formula field. Something like following for the formula field.
IIf(IsNull([CF1]), "Not Defined", [CF1])
lunedì 21 maggio 2012 09:10
you can read the project dataset from working store in the OnCreated event. You can create or update customfields,call the queue addTo/update project methods and the QueuePublishSummaryMethod to reflect the changes.
And if you want to set a value for a custom field that is not mandatory ( so there´s no value for the customfield while the project is beeing created ), you´ve to add a new customfield row in the project dataset and call the queue addto project method.
The benefit of doing this within a eventhandler is that you´re able to check values against 3rd party systems/databases etc.
If you don´t need the checking then Kashif´s solution is the one you should use.