- Tue Sep 13, 2016 7:27 am
#786567
REST API Experts,
We are using custom PHP pages to create a new case. The case is getting created and is shown in draft folder. Before we show the dynaform we are using get variable to assign to the form. When we check why this is not working we saw not all variables are getting fetched using the api.
Below is the code we have used to check what we are getting when we use get variable.
We are using custom PHP pages to create a new case. The case is getting created and is shown in draft folder. Before we show the dynaform we are using get variable to assign to the form. When we check why this is not working we saw not all variables are getting fetched using the api.
Below is the code we have used to check what we are getting when we use get variable.
Code: Select all
I have also attached the php file:
function getVariables($url, $ws, $token, $app)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url.'/api/1.0/'.$ws.'/cases/'.$app.'/variables');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$token));
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
$variables = getVariables($_SESSION['url'], $_SESSION['ws'], $_SESSION['access_token'], $caseid);
$variables = json_decode($variables, true);
Code: Select all
<!-- REST Connection Start -->
<?php
session_start();
if(is_null($_SESSION['access_token']))
header('Location: index.html');
function createcaseVar($url, $ws, $token, $proj, $task)
{
$aVars = array(
'pro_uid' => $proj,
'tas_uid' => $task
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url.'/api/1.0/'.$ws.'/cases');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aVars));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$token));
$output=curl_exec($ch);
$output=json_decode($output,true);
$app_uid = $output['app_uid'];
curl_setopt($ch,CURLOPT_URL, $url.'/api/1.0/'.$ws.'/cases/'.$app_uid.'/variable');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aVars));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$token));
$Result=curl_exec($ch);
curl_close($ch);
return $output;
}
$caseoutput = createcaseVar($_SESSION['url'], $_SESSION['ws'], $_SESSION['access_token'], $_GET['proj'], $_GET['task']);
$caseid = $caseoutput['app_uid'];
$caseno = $caseoutput['app_number'];
function routeCase($url, $ws, $token, $app)
{
$putData = http_build_query($_POST);
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch,CURLOPT_URL, $url.'/api/1.0/'.$ws.'/cases/'.$app.'/variable');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$token));
curl_setopt($ch, CURLOPT_POSTFIELDS, $putData);
curl_exec($ch);
curl_setopt($ch,CURLOPT_URL, $url.'/api/1.0/'.$ws.'/cases/'.$app.'/route-case');
curl_exec($ch);
}
routeCase($_SESSION['url'], $_SESSION['ws'], $_SESSION['access_token'], $caseid);
function getDynaform($url, $ws, $token, $proj, $task,$caseid)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url.'/api/1.0/'.$ws.'/project/'.$proj.'/activity/'.$task.'/steps');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$token));
$steps=curl_exec($ch);
$steps = json_decode($steps, true);
/* $trig = getbeforetrigger($url, $ws, $token, $proj, $task,$steps[0]['step_uid']);
foreach($trig as $trigl)
{
var_dump($trigl['tri_uid']);
var_dump($trigl['st_type']);
var_dump($caseid);
if ($trig['st_type']=='BEFORE')
{
$ch1 = curl_init();
curl_setopt($ch1,CURLOPT_URL,$url.'/api/1.0/'.$ws.'/cases/'.$caseid.'/execute-trigger/'.$trigl['tri_uid']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch1,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch1,CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$token));
$result = curl_exec($ch1);
}
}*/
//$trig = json_decode($trig,true);
//var_dump($trig);
curl_setopt($ch,CURLOPT_URL,$url.'/api/1.0/'.$ws.'/project/'.$proj.'/dynaform/'.$steps[0]['step_uid_obj']);
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
$dynaform = getDynaform($_SESSION['url'], $_SESSION['ws'], $_SESSION['access_token'], $_GET['proj'], $_GET['task'],$caseid);
$dynaform = json_decode($dynaform, true);
function getVariables($url, $ws, $token, $app)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url.'/api/1.0/'.$ws.'/cases/'.$app.'/variables');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$token));
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
$variables = getVariables($_SESSION['url'], $_SESSION['ws'], $_SESSION['access_token'], $caseid);
$variables = json_decode($variables, true);
function getbeforetrigger($url, $ws, $token, $proj, $task,$stepuid)
{
// /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid}/available-triggers/{type}
$type="before";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url.'/api/1.0/'.$ws.'/project/'.$proj.'/activity/'.$task.'/step/'.$stepuid.'/triggers');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$token));
$steps=curl_exec($ch);
$steps = json_decode($steps, true);
return $steps;
}
// var_dump($dynaform);
?>
<!-- REST Connection End -->
<?php include_once("header1.php");
$content = json_decode($dynaform['dyn_content'], true);
//var_dump($content['items'][0]['script'][code]);
echo "<script type='text/javascript'>".$content['items'][0]['script'][code]."</script>" ; ?>
<!-- Page Content Start-->
<div>
<h3>Dynaform: <?php echo $dynaform['dyn_title'] ?></h3>
<h5>Case ID: <?php echo $caseno ?></h5>
<form action="route_case.php?app=<?php echo $caseid ?>" method="post">
<table align="center" class="table" style="background-color:#F2F2F2; width: 90%;">
<?php $content = json_decode($dynaform['dyn_content'], true);
foreach($content['items'][0]['items'] as $field) {
echo "<tr>";
for($i = 0 ; $i<=count($field)-1 ; $i++){
if(isset($field[$i]['mode']))
$mode = $field[$i]['mode'] == 'view'? " disabled" : "";
if(isset($field[$i]['var_name']))
$value = array_key_exists($field[$i]['var_name'], $variables)? $variables[$field[$i]['var_name']] : "";
switch($field[$i]['type']){
case "title":
echo "<th style='background-color:#1192d4; color:#FFF; font-size: 17px;' colspan='".(12 / count($field))."'>".$field[$i]['label']."</th>";
break;
case "subtitle":
echo "<th style='background-color:#4EAECE; color:#FFF; font-size: 15px;' colspan='".(12 / count($field))."'>".$field[$i]['label']."</th>";
break;
case "text":
echo "<td colspan='".(12 / count($field))."'><label>".$field[$i]['label']."</label>
<input name='".$field[$i]['var_name']."' class='form-control'".$mode." value='".$value."'>
</td>";
break;
case "textarea":
echo "<td colspan='".(12 / count($field))."'><label>".$field[$i]['label']."</label>
<textarea name='".$field[$i]['var_name']."' class='form-control' placeholder='".$field[$i]['placeholder']."' rows='3'".$mode.">".$value."</textarea></td>";
break;
case "dropdown":
echo "<td colspan='".(12 / count($field))."'><label>".$field[$i]['label']."</label><select name='".$field[$i]['var_name']."' class='form-control'".$mode.">";
foreach($field[$i]['options'] as $option){
$selected = $value == $option['value']? "selected": "";
echo "<option value='".$option['value']."' ".$selected.">".$option['label']."</option>";
}
echo "</select></td>";
break;
case "radio":
echo "<td colspan='".(12 / count($field))."'><label>".$field[$i]['label']."</label>";
foreach($field[$i]['options'] as $option){
$selected = $value == $option['value']? " checked": "";
echo "<div class='radio'><label><input name='".$field[$i]['var_name']."' type='radio' value='".$option['value']."'".$mode.$selected.">".
$option['label']."</label></div>";
}
echo "</td>";
break;
case "submit":
echo "<td align='center' colspan='".(12 / count($field))."'><input class='btn btn-info' type='submit' value='".$field[$i]['label']."'></td>";
break;
case "js":
echo "<script type='text/javascript'>".$field[$i]['code']."</script>" ;
break;
}
}
echo "</tr>";
}
?>
</table>
</form>
</div>
<!-- Page Content End-->
<?php include_once("footer.html"); ?>