Is dojo.xhrGet supported in calculated value scripts?

Question:
Can I use dojo.xhrGet in a custom script of calculated values to fetch timeline details?
Environment:
EWM 7.0.2
Application: Work Items -> Attribute Customization -> Script-based Value Provider
This is my xhrGet code :-
var xhrGet = dojo.xhrGet({
url: projectTimeline,
handleAs: "xml",
sync: true,
load: function(response) {
var xmlDoc = response.documentElement;
var timelines = xmlDoc.getElementsByTagName("values");
for (var i = 0; i < timelines.length; i++) {
var iterations = timelines[i].getElementsByTagName("iterations");
for (var j = 0; j < iterations.length; j++) {
var id = iterations[j].getElementsByTagName("id")[0].textContent;
if (id === Iteration) {
var timelineLabel = timelines[i].getElementsByTagName("label")[0].textContent;
console.log("Timeline Label:", timelineLabel);
return;
}
}
}
},
error: function(error) {
console.error("Error fetching XML:", error);
}
});
Error in ccm.log:-
Error invoking value provider 'CustomURLProvider' associated with the attribute 'Link' in the project area with id '<projectAreaId>'.
You can link to the project area definition using a URL similar to
https://<hostname>:9443/jazz/process/project-areas/<projectAreaId>,
where the host name, port and jazz context are configured for your installation.
Contact your project area administrator for assistance.
" com.ibm.team.rtc.common.scriptengine.UnknownTypeException: '<custom.class.name>' is not a constructor
at com.ibm.team.rtc.common.scriptengine.environment.ScriptingHelperImplementation.getConstructor(ScriptingHelperImplementation.java:162) ~[?:?]
at com.ibm.team.rtc.common.scriptengine.ScriptUtilities$1.run(ScriptUtilities.java:30) ~[?:?]
at com.ibm.team.rtc.common.scriptengine.environment.AbstractScriptEnvironment.execute(AbstractScriptEnvironment.java:74) ~[?:?]
If I remove/comment the xhrGet part, the script runs without errors.
->Is dojo.xhrGet actually supported in calculated value scripts, or is there another supported way to fetch timeline/iteration details from the server?
3 answers

(function() {
const jazzClient = jazz.client;
const xhrArgs = {
url,
headers : { 'Accept' : 'application/json' },
handleAs : 'json'
};
jazzClient.xhrGet(xhrArgs).then(response => {}


Cannot find function xhrGet in object [object Object]
dojo.provide("com.URLGenerator");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
dojo.declare("com.URLGenerator", null, {
getValue: function(attribute, workItem, configuration) {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var customWorkItemAttributeTool = workItem.getLabel('com.rtc.configuration.workitemtype.customattribute.tool');
var workflowType = workItem.getValue(WorkItemAttributes.TYPE);
var workflowState = workItem.getValue(WorkItemAttributes.STATE);
var Iteration = workItem.getValue(WorkItemAttributes.PLANNED_FOR);
var category = workItem.getLabel(WorkItemAttributes.FILED_AGAINST);
var workitemid = workItem.getValue(WorkItemAttributes.ID);
var result = "";
var timelineLabel = "Unassigned";
if (!workflowState || customWorkItemAttributeTool === "Unassigned") {
result = "";
} else {
category = category ? category.replace(/[^A-Z0-9]/ig, " ").replace(/\s+/g, "") : "Unassigned";
var serverKey = "serverKey";
if (configuration && configuration["serverKey"]) {
serverKey = configuration["serverKey"];
}
var ProjectArea = workItem.getValue(WorkItemAttributes.PROJECT_AREA);
var projectTimeline = "https://alm-ccm-server/ccm/service/com.ibm.team.workitem.common.internal.rest.IWorkItemRestService/timelinesWithIterations?projectAreaItemId=" + ProjectArea + "&includeArchived=false&requireDeliverable=false";
try {
var xhrGet = dojo.xhrGet({
url: projectTimeline,
handleAs: "xml",
sync: true,
load: function(response) {
console.info('response', response);
var xmlDoc = response.documentElement;
var timelines = xmlDoc.getElementsByTagName("values");
for (var i = 0; i < timelines.length; i++) {
var timeline = timelines[i];
var iterations = timeline.getElementsByTagName("iterations");
for (var j = 0; j < iterations.length; j++) {
var iteration = iterations[j];
var id = iteration.getElementsByTagName("id")[0].textContent;
if (id === Iteration) {
timelineLabel = timeline.getElementsByTagName("label")[0].textContent;
console.log("Timeline Label-2:", timelineLabel);
}
}
}
if (!timelineLabel) {
console.log("Timeline not found for Iteration:", Iteration);
timelineLabel = "Unassigned";
}
},
error: function(error) {
console.error('Error occurred while fetching XML:', error);
}
});
timelineLabel = timelineLabel.replace(/[^A-Z0-9]/ig, " ").replace(/\s+/g, '');
result = "targetBaseURL" +
"/" + workitemid +
"/" + timelineLabel +
"/" + category +
"/" + serverKey +
"/0";
} catch (e) { --> enters only on click of Save button of WI (unable to debug)
if (e instanceof TypeError) {
console.log("Error in estimationtoolurl script:", e);
result = workItem.getLabel('com.rtc.configuration.workitemtype.customattribute.link');
} else {
result = "Error in estimationtoolurl script:" + (e.message || e.toString()); // all I get from this kind of error message is Cannot find function xhrGet in object [object Object]
}
}
}
return result;
}
});
})();
com.rtc.configuration.workitemtype.customattribute.tool -> a enumeration
com.rtc.configuration.workitemtype.customattribute.link -> a small html, where I want to place my generated url.
Comments

1 vote

Davyd Norris, yes I did try.
As you mentioned, the script runs perfectly without any errors in the web browser — the URL gets generated without issues there.
However, the problem is in the ALM server logs (ccm.log). I used to get the error:
Error invoking value provider 'URLGenerator' associated with the attribute 'Link' in the project area with id ... "com.URLGenerator" is not a constructor.
So, I tried adding the xhrGet / your suggested jazzClient.xhrGet inside a try-catch block. After that, the issue in the logs disappeared.
But when I try to save the work item, the previously generated URL (already present in the Link attribute, generated seconds before the save) throws the following errors-
Error in estimationtoolurl script: "jazz" is not defined (from your suggestion), or
Cannot find function xhrGet in object [object Object] (from dojo.xhrGet).
Both are type errors. What I need is either a way to properly catch the error and always show the generated URL in all scenarios.
