Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi team
Do a search for 'transaction' in the WRS 2.2 manual (link 1 below). I get 8 hits. In particular, the 8 page section 'Processing HTTP Requests for OData URLs' starting at p.45 is necessary reading. I wish it contained an example.
Clearly the transaction mechanism is intended to guard POST requests. And see 'Change sets do not support the GET operation.' on page 80. Now there is an example, thanks!
Now my question: suppose that you need to make two GET requests in succession for a report, and Windchill data can change between the requests. What algorithm can be used to ensure consistency?
Perhaps some sort of consistency checking, followed by a retry?
REST principles are important (link 2 below)
cheers -- Rick
https://stackoverflow.com/questions/33060968/rest-and-transaction-rollbacks
It might be good practice to synchronise the GET requests - so that the second request is only made after the first is successful and so on.
For example, you might want to GET a CSRF Nonce then use the response in the next GET and then wait for a complete response before the next function.
Here's an example of a synchronous chain of requests and functions using JQuery.
.then is used to make sure the function is called only when the previous function is done, ajax and jquery handles everything else
//E:\ptc\Windchill_11.1\Windchill\codebase\netmarkets\jsp\test\getAllContexts.js
$(document).ready(function() {
$.ajax({
url:
"http://<myWindchillHost>/Windchill/servlet/odata/PTC/GetCSRFToken()",
headers: {
'Accept': 'application/json',
}
}).then(function(data) {
var req_headers = {};
req_headers['Content-Type'] = "application/json";
req_headers['Accept'] = "application/json";
req_headers['CSRF_NONCE'] = data.NonceValue;
req_headers['Task'] = "com/ptc/windchill/enterprise/report/ExecuteReportTemplate2.xml";
dashdata = {"Task":"com/ptc/windchill/enterprise/report/ExecuteReportTemplate2.xml","Params":[{"Value":"wt.query.template.ReportTemplate:657775537","Name":"object_ref","ValueSet":[]},{"Value":"1038 - some text","Name":"Context","ValueSet":[]}]};
//console.log(req_headers);
//console.log(dashdata);
$.ajax({
type: "POST",
url: "http://<myWindchillHost>:80/Windchill/servlet/odata/v1/IE/InvokeIETask?%24count=true",
headers: req_headers,
data: JSON.stringify(dashdata)
}).then(function(data2) {
for (i = 0; i < data2.value[0].Elements.length; i++) {
$('.table-content').append( "<tr><td>" + data2.value[0].Elements[i].Attributes[0].Value + "</td><td>" + data2.value[0].Elements[i].Attributes[1].Value + "</td></tr>" );
}
});
});
});
For context, this how the above request is consumed, it's a simple HTML page which lists all the names and IDs Windchill products, libraries and projects
//E:\ptc\Windchill_11.1\Windchill\codebase\netmarkets\jsp\test\getAllContexts.jsp
<!DOCTYPE html>
<html>
<head>
<title>Get All Contexts</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="getAllContexts.js"></script>
</head>
<body>
sample usage: http://<myWindchilHost>/Windchill/netmarkets/jsp/test/getAllContexts.jsp
<p class="GetPartStructure">
<table class="table-content" border=1 cellspacing=0 cellpadding=3 />
<tr>
<td class="heading1">Context Name</td>
<td class="heading2">Context ID</td>
</tr>
</p>
</table>
</body>
</html>
Hi rhart
You can chain those requests in javascript but they are still separate REST GET's and POST's. Beware of doing anything stateful in the javascript. See
https://stackoverflow.com/questions/1389881/transaction-in-rest-wcf-service/1390393#1390393
I was mistaken to think of transactions for this.
The subject of ODATA 'navigation' might be worth discussing. I find the doco for this really confusing, because of a lack of examples. If it works as I suspect, then it can be used for some table joins (and possibly some quite complex joins). Then I would not need multiple GET's or any transaction. It's time for a separate thread on 'navigation'! I will start one when I get a mo.
cheers
Rick