Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By kyy1rds
#790571
The specific problem I'm having is my calls to PMFNewCase() is only returning zeros as I loop through an array of records queried from a PM Table of imported data.

Background:
I need to pull data from an external database and create new cases for each record. Those new cases need to be routed to other personnel for their input. They submit the record back to the administrating manager for approval and create the queries that update the original table in the source database to post the changes back to the original database.

We started out trying to do all this in one process but found that the task of creating new tasks would be recursive so we broke out the task of creating the new cases that will be distributed to managers for review and edit into a separate process. So In the initial process (call it "Prepare Cases"), we query the userUid, processUID, and the taskUID and store the values in variables. The new case is in a different process, using a different task and user.
--------------------------------------------------------------------------------------------------------
Code: Select all
//Get the userUid for the manager that start the case
@@userUid = executeQuery("select usr_uid from users where usr_firstname = 'Gal'");

//Get process UID
@@processUid = PMFGetProcessUidByName("Update Course Offering");

@@taskUid = PMFGetTaskUID("Update Course Information" ,@@processUid);

@@gridCases = executeQuery("Select * from PMT_Course where Department = 'ACCT'");  

if (is_array(@@gridCases)){
   foreach (@@gridCases as @@row) {
      
      //create a new case for each course
      @@caseUid = PMFNewCase($processId, $userId, $taskId, @@row);
 
      //if there was an error, $newCase will be zero, otherwise it //will have the new case UID
      //populate the new case with the variable values from the database row
      if (@@caseUid) {
         $c = new Cases();
         $aCase = $c->loadCase(@@caseUid);
         $aCase['APP_STATUS'] = 'TO_DO';
         $c->updateCase(@@caseUid, $aCase);
         echo "case status '$aCase{['APP_STATUS']}'";
      }
   }
}
The PMT_Course table has columns of the same name as the variables in the process but the process creating the new case doesn't have the same state variables. They only exist in this process as query results being passed as array variables to PMFNewCase(). What am I doing incorrectly? And is there a better way to structure the process so that it's easily maintainable by less technical personnel?

Thanks!
Robert
By mishika
#790578
Hello,

Did you run this in Debug mode?
Are you getting correct values for @@processUid, @@taskUid, @@userUid.
Also, you have values stored in case variables(like @@processUid) and you have passed the PHP variables($processId) in the function PMFNewCase().
You should pass the case variables only to the function if you are storing values in them.
Please run this in debug mode and check whether the values assigned to the variables are correct or not.

Hope this helps

Best Regards
Mishika
By kyy1rds
#790583
Hi Mishika,

Thanks for that second set of eyes! I was using $processid, $taskid, and $userid before and then wanted to check it in debugger so I changed them over to case variables.

Yes, I'm running in debug mode and I see the correct values in the Debugger to the right of the screen for the processUid, taskUid and userUid. I tested them both by running queries directly to the database (to the users, process, and task tables) and comparing the results. it all seems in order, but I still don't get cases created. Is there something I need to have present that is missing? I've added permission for these members/users to get access to the new cases when they show up in their email inbox. So far, it's not working.

Any ideas?

Robert
User avatar
By amosbatto
#790585
You are converting an array into a string in your list of variables.

To pass an array of variables to the new case, change this line:
@@caseUid = PMFNewCase($processId, $userId, $taskId, @@row);
To:
@@caseUid = PMFNewCase($processId, $userId, $taskId, @=row);

Make sure that your @=row has a format like this:
Code: Select all
@=row = array(
   'string_variable1' => 'string1',
   'float_variable2' => 342.23,
   'date_variable3' => '2016-01-31',
   'datetime_variable4' => '1999-12-02 23:59:59'
);
Also remember that the user "Gal" needs to be in the assignment pool for the "Update Course Information" task and that task has to have a starting event attached to it.
By kyy1rds
#790609
Thanks, Amos, for the heads up on case variable type conversion. I went back to read up on it at http://wiki.processmaker.com/3.0/Triggers. That was useful. But I'm still not getting my cases created.

I'm dumping the content of row from the Debugger to make sure the structure for the array is correct. All these variables are defined in the "Variables" list for the case. I'm including processUid, userUid, and taskUid values at runtime as well.

caseUid: 0
processUid: 26373291058b6d67f421393096844597
userUid: Array ( [1] => Array ( [usr_uid] => 91232299858efd3bd4fd106040522878 ) )
taskUid: 47137451158b889adca8bc4066385803
row: Array ( [N] => 4 [SSBSECT_TERM_CODE] => 201701 [SSBSECT_CRN] => 10009 [SSBSECT_SUBJ_CODE] => ACCT [SSBSECT_CRSE_NUMB] => 2102 [SSBSECT_CRSE_TITLE] => [SSBSECT_PTRM_CODE] => 1 [SSRMEET_START_DATE] => 0000-00-00 [SSRMEET_END_DATE] => 0000-00-00 [SSRMEET_CATAGORY] => T [DAYS] => 1300 [SSRMEET_BEGIN_TIME] => 00:14:15 [SSRMEET_END_TIME] => 00:00:00 [SSRMEET_BLDG_CODE] => [SSRXLST_XLST_GROUP] => A [SSBSECT_CAMP_CODE] => 3 [SSBSECT_MAX_ENRL] => 334 [SSBSECT_ENRL] => 0 [SSBSECT_SSTS_CODE] => A [SIRASGN_PIDM] => 4230865 [LAST_NAME] => Partridge [FIRST_NAME] => Kathleen [SSBSECT_VOICE_AVAILABLE] => 0 [SSBSECT_PRIOR_ENRL] => 332 [DEPARTMENT] => ACCT )

gridCases: Array ( [1] => Array ( [N] => 4 [SSBSECT_TERM_CODE] => 201701 [SSBSECT_CRN] => 10009 [SSBSECT_SUBJ_CODE] => ACCT [SSBSECT_CRSE_NUMB] => 2102 [SSBSECT_CRSE_TITLE] => [SSBSECT_PTRM_CODE] => 1 [SSRMEET_START_DATE] => 0000-00-00 [SSRMEET_END_DATE] => 0000-00-00 [SSRMEET_CATAGORY] => T [DAYS] => 1300 [SSRMEET_BEGIN_TIME] => 00:14:15 [SSRMEET_END_TIME] => 00:00:00 [SSRMEET_BLDG_CODE] => [SSRXLST_XLST_GROUP] => A [SSBSECT_CAMP_CODE] => 3 [SSBSECT_MAX_ENRL] => 334 [SSBSECT_ENRL] => 0 [SSBSECT_SSTS_CODE] => A [SIRASGN_PIDM] => 4230865 [LAST_NAME] => Partridge [FIRST_NAME] => Kathleen [SSBSECT_VOICE_AVAILABLE] => 0 [SSBSECT_PRIOR_ENRL] => 332 [DEPARTMENT] => ACCT ) )

...and in posting this information I think I found the problem with userUid coming in as an array when I should probably convert it to a string. Let me try it now...
---update----
So, I changed the reference of the array value stored in userUid to this:
Code: Select all
@@userUid = executeQuery("select usr_uid from users where usr_firstname = 'Gal'");

//Get process UID
@@processUid = PMFGetProcessUidByName("Update RCB Course Offering");


@@taskUid = PMFGetTaskUID("Update Course Information" ,@@processUid);


@@gridCases = executeQuery("Select * from PMT_Course where Department = 'ACCT'");  //changed the data so this only brings back one record for testing...

if (is_array(@@gridCases)){
foreach (@@gridCases as @@row){
//create a new case for each course
@@caseUid = PMFNewCase(@@processUid, @@userUid[1].[usr_uid], @@taskUid, @=row);

//if there was an error, $newCase will be zero, otherwise it 
//will have the new case UID
//"turn on" the new case by changing the status to TO_DO so user can see it in the Inbox...
if (@@caseUid){
	$c = new Cases();
   	$aCase = $c->loadCase(@@caseUid);
  	$aCase['APP_STATUS'] = 'TO_DO';
  	$c->updateCase(@@caseUid, $aCase);
	}
}
}
-------------------------------------
What do you think? It's still not creating the case.

rds
User avatar
By amosbatto
#790610
You are not accessing the user ID correctly. It should be:
Code: Select all
@@caseUid = PMFNewCase(@@processUid, @@userUid[1]['usr_uid'], @@taskUid, @=row);
If that doesn't work, then remove @=row to see if that is the problem:
Code: Select all
@@caseUid = PMFNewCase(@@processUid, @@userUid[1]['usr_uid'], @@taskUid, array());
If that doesn't work, then set the IDs manually in your code:
Code: Select all
@@processUid = 'XXXXXXXXXXXXXXXXXXXXXXXX';
@@taskUid = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
@@userUid = 'XXXXXXXXXXXXXXXXXXXXXXXX';
If you keep eliminating potential problems in the code, eventually you will figure out what is wrong.

In most instances when PM Functions fail, they will define @@__ERROR__ (which you can see in the debugger) with a error message to tell you what is the problem.
By kyy1rds
#790632
We have a caseid!
I had to set the parameters as literal strings instead of using the return variables from the query and function calls and it worked.

Before that I checked the Debugger for errors and didn't find any. I highlighted each variable to see if the lower window in the debugger would populate with a message, but nothing doing.

I need to figure out how to get this to work by looping through a thousand records and creating a new case for each set of case variables. But this moves me forward.

Thanks for all your help!

Robert

Hello! If you did not find the mcrypt extension […]

Hello! You have a mistake in the url, the correct […]

objects variable in grid

Hello! It is very rare since I could not replicate[…]

Hello! It is likely that the design you are doin[…]