This error seems to be around the following line. Removing it moves to an error further down the page but it's one that I think relates to this line anyway
self::$incidentOneId = $incidentOne->ID;
If I change it to the following, the above error disappears but I then get this
When I tested the CPM directly without creating system attribute (UTC->CTC), I saw the same error that you posted here ( 'Validation failed on create of a Incident' ).
But when I tested the same CPM after creating the system attribute, I am not seeing the error. The test harness passed.
So, I believe, the error is with the line '$incidentOne->CustomFields->CTU->CTC = 1264' trying to set value to an attribute that doesn't exist in the site.
Please verify that the 'CTU->CTC' of type Integer exists on Incident in the site that you are testing.
/**
* Set up test cases.
*/
public static function setup()
{
// First test
$incidentOne = new RNCPHP\Incident;
$cont = RNCPHP\Contact::fetch(38467);
$incidentOne->PrimaryContact = $cont;
$incidentOne->Subject = '123456';
$incidentOne->save();
self::$incidentOneId = $incidentOne->ID;
// Second test
$incidentTwo = new RNCPHP\Incident;
$cont = RNCPHP\Contact::fetch(38467);
$incidentTwo->PrimaryContact = $cont;
$incidentTwo->Subject = '654321';
$incidentTwo->save();
self::$incidentTwoId = $incidentTwo->ID;
}
/**
* Return the object that we want to test with. You could also return
* an array of objects to test more than one variation of an object.
* @param int $action
* @param class $object_type
* @return object | array
*/
public static function fetchObject($action, $object_type)
{
$incidentOne = $object_type::fetch(self::$incidentOneId);
$incidentTwo = $object_type::fetch(self::$incidentTwoId);
return array($incidentOne, $incidentTwo);
}
/**
* Validate test cases
* @param int $action
* @param object $incident
* @return bool
*/
public static function validate($action, $incident)
{
if (RNCPM\ActionUpdate == $action)
{
if (assert($incident->Subject== "123456"))
{
echo "Update test passed\n";
return true;
}
else
{
echo "Update test FAILED\n";
}
}
elseif (RNCPM\ActionCreate == $action)
{
if (assert($incident->Subject == "654321"))
{
echo "Create test passed\n";
return true;
}
else
{
echo "Create test FAILED\n";
}
}
else
{
echo "Invalid action";
}
return false;
}
/**
* Destroy every object created by this test. Not necessary since in
* test mode and nothing is committed, but good practice if only to
* document the side effects of this test.
*/
public static function cleanup()
{
if (self::$incidentOneId)
{
$incidentOne = RNCPHP\Incident::fetch(self::$incidentOneId);
$incidentOne->destroy();
self::$incidentOneId = null;
}
Back story - there is a custom object called CTU.CTC which has the relationship set as below. This is where the custom field in the incident has come from. With this in mind - is there anything else I need to have done?
Comment
Are you able to execute this block of code in a custom script?
Also, maybe you should use SuppressAll with Incident save under ActionUpdate.
Be the first to rate this
|
Sign in to rate this
Yes - if I dump into a model and call it via a controller - it creates an incident just fine against my name.
Added SuppressAll and the error still happens
Be the first to rate this
|
Sign in to rate this
Be the first to rate this
|
Sign in to rate this
Unless you have specific reason, why not return true from Validate() method in Test Harness...
~Suresh
Be the first to rate this
|
Sign in to rate this
You are creating two incidents in setup(). In the validate() method, you may have to check the CTC for both Incidents.
Something like
if (assert($incident->CustomFields->CTU->CTC == 1265) || assert($incident->CustomFields->CTU->CTC == 1264))
{
echo "Create test passed\n";
return true;
}
else
{
echo "Create test FAILED\n";
}
Be the first to rate this
|
Sign in to rate this
I still get the same error - the error is on creation of the test incidents
Strangely, the line number points to an empty line
Be the first to rate this
|
Sign in to rate this
This error seems to be around the following line. Removing it moves to an error further down the page but it's one that I think relates to this line anyway
If I change it to the following, the above error disappears but I then get this
Be the first to rate this
|
Sign in to rate this
I just tried this in a test site.
When I tested the CPM directly without creating system attribute (UTC->CTC), I saw the same error that you posted here ( 'Validation failed on create of a Incident' ).
But when I tested the same CPM after creating the system attribute, I am not seeing the error. The test harness passed.
So, I believe, the error is with the line '$incidentOne->CustomFields->CTU->CTC = 1264' trying to set value to an attribute that doesn't exist in the site.
Please verify that the 'CTU->CTC' of type Integer exists on Incident in the site that you are testing.
Regards, Venkat B
Be the first to rate this
|
Sign in to rate this
I copied the example from http://cxdeveloper.com/article/cpms-101-introduction-custom-process-models - this worked fine
Changed all references from contact to incident and it falls over. Absolutely stumped
I made sure I gave it a primary contact via
Be the first to rate this
|
Sign in to rate this
This is what I get looking at the type - but even if I remove that line where it saves, it still errors
CTU.CTC is a custom object with a relationship to the Incident table
Be the first to rate this
|
Sign in to rate this
Here is my basic code
Be the first to rate this
|
Sign in to rate this
Validate() method will be tested for both create and update actions. Please match $Incident->Subject that is being validated in the validate method.
I updated your code with the following lines and tested. It worked.
$incidentOne->Subject = '123456';
$incidentTwo->Subject = '123456';
if (assert($incident->Subject== "123456"))
if (assert($incident->Subject == "123456"))
Pls give a try.
Regards, Venkat B
Be the first to rate this
|
Sign in to rate this
When saving the custom field below, it doesn't.
Back story - there is a custom object called CTU.CTC which has the relationship set as below. This is where the custom field in the incident has come from. With this in mind - is there anything else I need to have done?
Be the first to rate this
|
Sign in to rate this
Then its Foreign Key so it should be like $incidentOne->CustomFields->CTU->CTC = RNCPHP\CTU\CTC::fetch(1264);
~Suresh
Be the first to rate this
|
Sign in to rate this
The error is still in the apply() function despite using RNCPHP\CTU\CTC::fetch(1264);
Be the first to rate this
|
Sign in to rate this