Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hello Everyone,
I'm working with Windchill 13.0 and need to add a simple action button to the Windchill interface that can call my custom API functions.
Here’s what I want to achieve:
1) Add a button to the Windchill UI.
2) When the button is clicked, it should trigger a JavaScript function that calls a Windchill OData API.
Here’s an example of the API function I want to call(will be using a java version of this function):
async function getParts() {
const apiUrl = "http://windchill.gosaas.io:80/Windchill/servlet/odata/v6/ProdMgmt/Parts?$count=false";
const username = "ahsan";
const password = "Tartan123";
const basicAuth = 'Basic ' + btoa(username + ':' + password);
try {
const response = await fetch(apiUrl, {
method: 'GET',
headers: {
'Authorization': basicAuth,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching parts from Windchill:', error);
throw error;
}
}
I’m not sure how to add a custom button to the Windchill UI and link it to this function. Could anyone provide a step-by-step guide or any example code to help me achieve this?
Thank you in advance for your assistance!
Best regards,
The problem with this plan is that OData requires authentication in the form of https://username:pw@domain/...
Corrections please!
You don't have an easy way to provide the authentication (other than a popup to prompt the user each time). See my questions from a few months ago (the search function here makes that difficult).
The correct way would be to modify
$WINDCHILL/config/actions/ChangeManagement-actionModels.xml
$WINDCHILL/config/actions/ChangeManagement-actions.xml
or /config/actions/PartClient-actionmodels.xml etc and provide java class files installed in the appropriate places server-side. You need to understand how Windchill's Spring is architected.
As for the documentation we need... please share!