Quantcast
Channel: Discussion Forum > Connect Data Services
Viewing all articles
Browse latest Browse all 2504

CPM: Determine current state of the object (5 Comments)

$
0
0

Topic by Brad Leary

The following paragraph is from the CPM Wiki:

Only values that have been modified will be contained in $obj. If you need access to values that have not been modified you may access the prev object. The prev object is passed as a child of $obj in the apply function ($obj->prev); this object is a snapshot of the object the CPM operates on at the point just prior to save.You may also use $obj and $obj-prev to compare how values have changed in an object.

I was very surprised to discover that $obj only represents changes to the object and not the current state.  So I'm trying to figure out how to determine what the current state is, but I feel like there is not enough information to distinguish between a value that did not change and a value that changed to a null.

So let's say I create an incident and set 3 custom fields.  I think the object would look like this:
$obj->CustomFields->c->field1 = 1
$obj->CustomFields->c->field2 = 2
$obj->CustomFields->c->field3 = 3
$obj->prev->CustomFields->c->field1 = null
$obj->prev->CustomFields->c->field2 = null
$obj->prev->CustomFields->c->field3 = null

Now let's say I change field1 to 100, field2 to null, and leave field3 alone.  Then I think the object would look like this:
$obj->CustomFields->c->field1 = 100
$obj->CustomFields->c->field2 = null
$obj->CustomFields->c->field3 = null
$obj->prev->CustomFields->c->field1 = 1
$obj->prev->CustomFields->c->field2 = 2
$obj->prev->CustomFields->c->field3 = 3

Is that right?  Is there any way for me to determine that the current value of field2 is null and the current value of field3 is still 3?

 

Edit:  I have since learned that this behavior only applies to CustomFields.


Viewing all articles
Browse latest Browse all 2504

Trending Articles